gpt4 book ai didi

javascript - 联系表单 mailer.php 返回空白页面

转载 作者:行者123 更新时间:2023-12-03 11:27:39 24 4
gpt4 key购买 nike

联系表单工作正常,直到我尝试添加 reCAPTCHA。我已经设法使 reCAPTCHA 出现,有 recaptchalib 和 mailer.php (显示空白页面的页面)。有什么想法我做错了吗?

这是mailer.php

<?php 
if(isset($_POST['submit'])) {

// check reCAPTCHA information
require_once('recaptchalib.php');

$privatekey = "privatekey";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);

// if CAPTCHA is correctly entered!
if ($resp->is_valid) {
// great success!
$myemail = "operations@socialmarketing.com";

/* Check all form inputs using check_input function */
$name = $_POST['inputName'];
$email = $_POST['inputEmail'];
$subject = $_POST['inputSubject'];
$message = $_POST['inputMessage'];

/* Let's prepare the message for the e-mail */

$subject = "Message From LGBT campaign Contact Form";

$message = "

China LGBT Contact Form

Name: $name
Email: $email

Message:
$message

";

/* Send the message using mail() function */
mail($myemail, $subject, $message);

/* Redirect visitor to the thank you page */
header('Location: successPage.html#contact');

} else {
// alert the captcha is not correct

}
}?>

这是我的 HTML 页面,我已将其制作为 .php 页面

<div class="marketing">
<div class="intro" id="contact">
<h1>Contact Us</h1>
<p>If you would like to stay informed about our progress or would like to help with the campaign, please fill out this form to send us an email.</p>
<div class="panel-body">
<form name="contactform" id="contactform" action="mailer.php" class="form-horizontal" role="form" method="POST">


<div class="form-group">
<label class="col-lg-2 control-label">Name</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="inputName" placeholder="Your Name">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">Email</label>
<div class="col-lg-10">
<input type="email" class="form-control" name="inputEmail" placeholder="Your Email">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">Message</label>
<div class="col-lg-10">
<textarea class="form-control" rows="4" name="inputMessage" placeholder="Your message..."></textarea>
</div>
</div>

<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<p>Prove you are not a spambot</p>
<?php require_once('recaptchalib.php');
$publickey = "publickey";
echo recaptcha_get_html($publickey);
?>

</div>
</div>

<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button type="submit" class="btn btn-primary">Send Message</button>
</div>
</div>
</form>
</div>
</div>

任何对此的帮助将不胜感激。

非常感谢

解决方案

<form name="contactform" id="contactform" action="mailer.php" class="form-horizontal" role="form"  method="post">


<div class="form-group">
<label class="col-lg-2 control-label">Name</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="inputName" placeholder="Your Name">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">Email</label>
<div class="col-lg-10">
<input type="email" class="form-control" name="inputEmail" placeholder="Your Email">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">Message</label>
<div class="col-lg-10">
<textarea class="form-control" rows="4" name="inputMessage" placeholder="Your message..."></textarea>
</div>
</div>

<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<p>Prove you are not a spambot</p>
<?php require_once('recaptchalib.php');
$publickey = "6Le0ff0SAAAAAOCeQiOcGUwQEfXERDyNJ";
echo recaptcha_get_html($publickey);
?>

</div>
</div>

<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<input type="submit" class="btn btn-primary" value="Send Message" name="submit">
</div>
</div>
</form>

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

if(isset($_POST['submit'])) {

// check reCAPTCHA information
require_once('recaptchalib.php');

$privatekey = "6Le0ff0SAAAALTDn4IkqNSN5F0AU2Ezhvf";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);

// if CAPTCHA is correctly entered!
if ($resp->is_valid) {
// great success!
$myemail = "kenm@socialmarketing.com";


/* Check all form inputs using check_input function */
$name = $_POST['inputName'];
$email = $_POST['inputEmail'];
$subject = "Message From LGBT campaign Contact Form";
$message = $_POST['inputMessage'];
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

/* Let's prepare the message for the e-mail */

$message = "

China LGBT Contact Form

Name: $name
Email: $email

Message:
$message

";

/* Send the message using mail() function */
mail($myemail, $subject, $message);

/* Redirect visitor to the thank you page */
header('Location: successPage.html#contact');

} else {

// alert the captcha is not correct
echo "captcha did not match!";
exit;

}
}?>

最佳答案

将按钮更改为:

<input type="submit" class="btn btn-primary" value="Send Message" name="submit">

POST 正在寻找名为 submit 的命名属性。

它基于您的条件语句,因此内部不会执行任何内容:

if(isset($_POST['submit'])) {...}

您也没有 named 表单元素来配合 $subject = $_POST['inputSubject'];

添加一个:

Subject:<input type="text" class="form-control" name="inputSubject" placeholder="Subject">

或者简单地测试:

$subject = "Form submitted";

您应该确保所有字段均已填写。如果主题留空或其他任何内容,您可能会因此而收不到邮件,尤其是电子邮件字段。

另一个原因可能是因为您没有正确的 header ,包括 From:

通过邮件访问 PHP.net 网站:

示例 From: 网站 header :

$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

并修改mail($myemail, $subject, $message);
mail($myemail, $subject, $message, $headers);

引用它们:

Note:

When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini.

Failing to do this will result in an error message similar to Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing. The From header sets also Return-Path under Windows.

<小时/>

添加error reporting到文件顶部,这将有助于查找错误。

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

// rest of your code

旁注:错误报告只能在暂存阶段完成,而不能在生产阶段完成。

关于javascript - 联系表单 mailer.php 返回空白页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26852610/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com