我的PHP表单不会向我发送电子邮件,并重定向到空白页

kn29

我已经研究了这个问题,但是我认为我找不到答案,因为我猜我个人的代码有问题。我尝试过各种尝试,尝试使我的PHP联系人表单提交并给我发送电子邮件,但是即使它已上传到服务器,它也无济于事。单击“提交”后,它仅显示一个空白页,而我输入到代码中的电子邮件地址根本没有电子邮件。我不知道自己缺少什么,因为我无法在任何地方找到解决问题的答案。

我确实注意到的一件事是,我的HTML中有一些与PHP中指定的必填字段不同的字段。但是,我不知道这有什么区别,因为我没有收到这些字段的任何错误消息或其他任何消息。如果您需要任何其他详细信息,请告诉我。感谢您的帮助。

的HTML

<form id="form_884913" method="post" action="send_form_email.php" class="appnitro">

这是我所有字段的所在,因此我省略了它,因为脚本很大。如果您需要任何帮助,请告诉我

HTML的其余部分

<input type="hidden" name="form_id" value="884913" />               
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
<input type="reset" value="Reset">

    </form> 

的PHP

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

// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "[email protected]";
$email_subject = "Contact";


function died($error) {
    // your error code can go here
    echo "We are very sorry, but there were error(s) found with the form you submitted. ";
    echo "These errors appear below.<br /><br />";
    echo $error."<br /><br />";
    echo "Please go back and fix these errors.<br /><br />";
    die();
}

// validation expected data exists
if(!isset($_POST['first_name']) ||
    !isset($_POST['last_name']) ||
    !isset($_POST['email']) ||
    !isset($_POST['telephone']) ||
    !isset($_POST['comments'])) {
    died('We are sorry, but there appears to be a problem with the form you submitted.');      
}

$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required

$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
 if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";

function clean_string($string) {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);
}

$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";


// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 
?>

<!-- include your own success html here -->

Thank you for contacting me! I will be in touch with you very soon.

<?php
 }
 ?>
孝太郎

如果要对HTML&PHP中的表单使用$_POST(与$_GET方法相同),则必须这样命名字段:

<input type="text" name="MyfieldName" value="1">

只有这样你才能打电话给你 $_POST['MyfieldName']

现在,如果您愿意echo $_POST['MyfieldName'];,它将返回1

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

CodeIgniter发送电子邮件将我重定向到“ // sendmail /”

向我发送电子邮件并重新启动tomcat攻击DDOS的脚本

停止cron向我发送电子邮件

php 脚本想法在我的 Windows 挂起时向我发送电子邮件

PHPMailer发送电子邮件并返回带有回显的空白页

PHP 表单(使用 POST)不提交或发送电子邮件,只显示一个空白页面

为什么cron甚至不重定向到/ dev / null也不会停止发送电子邮件

我如何设置在单击 <a href> 链接时自动向我发送电子邮件

为什么我的Web表单(PHP)无法正常工作(发送电子邮件)

从我的网站发送电子邮件

PHP邮件未发送电子邮件到我的电子邮件地址

从我的域本地发送电子邮件到域外的电子邮件

如何使crontab通过输出向我发送电子邮件?

有安全更新时,如何使服务器向我发送电子邮件?

如何允许用户在Crafter 3.0中向我发送电子邮件?

联系表格直接指向contact.php,但我不希望它重定向。(发送电子邮件确实有效)

发送电子邮件后如何重定向

Django:重定向后发送电子邮件

PHP表单发送空白电子邮件

为什么我的电子邮件表单发送电子邮件,有时却不发送电子邮件

Contact.php发送电子邮件但不重定向

使用googleusercontents img资源跟踪电子邮件并重定向到我的网站

使用googleusercontents img资源跟踪电子邮件并重定向到我的网站

为什么我不能从命令行向我的Gmail帐户发送电子邮件

每次从我的apache服务器访问某个文件时向我发送电子邮件

PHP电子邮件不会发送到我的电子邮件

无法使用 smtplib 向我的电子邮件发送附件

Rails 5 联系我表单不通过 heroku 使用 sendgrid 发送电子邮件

使用PHP和AJAX发送电子邮件表单