Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
防止PHP电子邮件表单显示空白页_Php_Email - Fatal编程技术网

防止PHP电子邮件表单显示空白页

防止PHP电子邮件表单显示空白页,php,email,Php,Email,我试图使用一些我在网上找到的代码,但我不懂PHP。表单可以工作,但在成功发送电子邮件后,浏览器URL窗口被设置为PHP文件,我只能知道如何在该区域编写纯文本。我想做的是重定向到当前html页面,或者,理想情况下,使用一些jQuery用一些文本替换标记的内容 提前感谢您的帮助 <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "email@emai

我试图使用一些我在网上找到的代码,但我不懂PHP。表单可以工作,但在成功发送电子邮件后,浏览器URL窗口被设置为PHP文件,我只能知道如何在该区域编写纯文本。我想做的是重定向到当前html页面,或者,理想情况下,使用一些jQuery用一些文本替换标记的内容

提前感谢您的帮助

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

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "email@email.email";
    $email_subject = "contact from website";

    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['t_name']) ||
        !isset($_POST['t_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.');       
    }



    $t_name = $_POST['t_name']; // required
    $t_interest = $_POST['t_interest']; // 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,$t_name)) {
    $error_message .= 'The Name you entered does not appear to be valid.<br />';
  }

  if(!preg_match($string_exp,$t_interest)) {
    $error_message .= 'The Interest 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 .= "Name: ".clean_string($t_name)."\n";
    $email_message .= "Interests: ".clean_string($t_interest)."\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); 

?>
function redirect(){
window.location.href = "http://getoutsideutah.org/donate.html";
}

<?php
}
?>

函数重定向(){
window.location.href=”http://getoutsideutah.org/donate.html";
}

发送一个包含您要转到的新URL的位置标题:

@mail($email_to, $email_subject, $email_message, $headers);

header("Location: http://getoutsideutah.org/donate.html");

函数重定向(){
标题(“位置:http://getoutsideutah.org/donate.html");
}

为什么不让PHP在邮件功能完成后进行重定向<代码>标题('位置:http://getoutsideutah.org/donate.html');如果要使用该重定向,则需要将其置于
标记之间。不要使用错误抑制运算符
@
,除非您希望代码因抑制错误而无明显原因停止工作。谢谢Peter!(还有戴夫!)。这样做效果很好,但是会将用户踢回上一页,而不会给他们任何关于消息成功发送的反馈。有什么方法可以替代吗?好的,你可以在会话中存储消息,但是如果你说你不懂PHP,也许你可以创建一个
Thank.html
页面,然后重定向到那里,而不是返回到
捐赠.html
页面。
    <?php
if(isset($_POST['email'])) {

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "email@email.email";
    $email_subject = "contact from website";

    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['t_name']) ||
        !isset($_POST['t_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.');       
    }



    $t_name = $_POST['t_name']; // required
    $t_interest = $_POST['t_interest']; // 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,$t_name)) {
    $error_message .= 'The Name you entered does not appear to be valid.<br />';
  }

  if(!preg_match($string_exp,$t_interest)) {
    $error_message .= 'The Interest 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 .= "Name: ".clean_string($t_name)."\n";
    $email_message .= "Interests: ".clean_string($t_interest)."\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); 
?>
function redirect(){
header("Location:http://getoutsideutah.org/donate.html");
}

<?php
}
?>