Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.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
Can';不要通过引导php发送电子邮件_Php_Html_Twitter Bootstrap - Fatal编程技术网

Can';不要通过引导php发送电子邮件

Can';不要通过引导php发送电子邮件,php,html,twitter-bootstrap,Php,Html,Twitter Bootstrap,我不知道为什么我的脚本不能正常工作。我使用的是bootstrap表单。当我填写表格并点击提交按钮时,我将重定向到空网页,如,但未发送任何内容: http://mywebpageaddress.com/send_form_email.php?comments=Hi%2C%0D%0Afirst+message%0D%0AJohn bootstrap index.html代码格式: <form action="send_form_email.php" method="post" class="

我不知道为什么我的脚本不能正常工作。我使用的是bootstrap表单。当我填写表格并点击提交按钮时,我将重定向到空网页,如,但未发送任何内容:

http://mywebpageaddress.com/send_form_email.php?comments=Hi%2C%0D%0Afirst+message%0D%0AJohn
bootstrap index.html代码格式:

<form action="send_form_email.php" method="post" class="form-horizontal">
          <div class="form-group">
            <label for="first_name" class="col-lg-2 control-label">First name</label>
            <div class="col-lg-10">
            <input type="text" class="form-control" id="first_name" name="first_name" placeholder="Enter you first name">
            </div>
          </div><!-- End form group -->

           <div class="form-group">
            <label for="last_name" class="col-lg-2 control-label">Last name</label>
            <div class="col-lg-10">
              <input type="text" class="form-control" id="last_name" name="last_name" placeholder="Enter you last name">
            </div>
          </div><!-- End form group -->

          <div class="form-group">
            <label for="email" class="col-lg-2 control-label">Email</label>
            <div class="col-lg-10">
              <input type="text" class="form-control" id="email" name="email" placeholder="Enter you Email Address">
            </div>
          </div><!-- End form group -->

          <div class="form-group">
            <label for="telephone" class="col-lg-2 control-label">Telephone</label>
            <div class="col-lg-10">
              <input type="text" class="form-control" id="telephone" name="telephone" placeholder="Enter you phone number">
            </div>
          </div>

          <div class="form-group">
            <label for="comments" class="col-lg-2 control-label">Any Message</label>
            <div class="col-lg-10">
              <textarea name="comments" id="comments" name="comments" class="form-control" 
              cols="20" rows="10" placeholder="Enter your Message"></textarea>
            </div>
          </div> 

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



        </form>

名字
姓
电子邮件
电话
有消息吗
提交
PHP文件:

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

    // CHANGE THE TWO LINES BELOW
    $email_to = "myemailt@gmail.com";

    $email_subject = "website html form submissions";


    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);  
?>

<!-- place your own success html below -->

Thank you for contacting us. We will be in touch with you very soon.

<?php
}
die();
?>

感谢您联系我们。我们将很快与您联系。
输出:

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

    // CHANGE THE TWO LINES BELOW
    $email_to = "myemailt@gmail.com";

    $email_subject = "website html form submissions";


    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);  
?>

<!-- place your own success html below -->

Thank you for contacting us. We will be in touch with you very soon.

<?php
}
die();
?>

感谢您联系我们。我们将很快与您联系。

您不需要在
表单
元素中设置方法。因此,默认情况下,它设置
get
。改变

<form action="send_form_email.php" method="post" class="form-horizontal">

并更改输入字段并设置名称,如:

<input type="text" class="form-control" id="first_name" name="first_name" placeholder="Enter you first name">


依此类推。

您不需要在
表单
元素中设置方法。因此,默认情况下,它设置
get
。改变

<form action="send_form_email.php" method="post" class="form-horizontal">

并更改输入字段并设置名称,如:

<input type="text" class="form-control" id="first_name" name="first_name" placeholder="Enter you first name">


依此类推。

您不需要在
表单
元素中设置方法。因此,默认情况下,它设置
get
。改变

<form action="send_form_email.php" method="post" class="form-horizontal">

并更改输入字段并设置名称,如:

<input type="text" class="form-control" id="first_name" name="first_name" placeholder="Enter you first name">


依此类推。

您不需要在
表单
元素中设置方法。因此,默认情况下,它设置
get
。改变

<form action="send_form_email.php" method="post" class="form-horizontal">

并更改输入字段并设置名称,如:

<input type="text" class="form-control" id="first_name" name="first_name" placeholder="Enter you first name">


等等。

我真的不建议使用php邮件功能,因为在我的情况下,有时它不起作用。。。此外,您没有在表单中设置方法,您必须将其设置为:

<form method="post" action="ha.php>

我真的不建议使用php邮件功能,因为在我的情况下,有时不工作。。。此外,您没有在表单中设置方法,您必须将其设置为:

<form method="post" action="ha.php>

我真的不建议使用php邮件功能,因为在我的情况下,有时不工作。。。此外,您没有在表单中设置方法,您必须将其设置为:

<form method="post" action="ha.php>

我真的不建议使用php邮件功能,因为在我的情况下,有时不工作。。。此外,您没有在表单中设置方法,您必须将其设置为:

<form method="post" action="ha.php>


可能要删除
@mail
中的
@
,因为它会抑制错误消息。另外,确定您使用的是
POST
还是
GET
。默认的表单方法是
GET
,但您的PHP需要
POST
。可能需要删除
@mail
中的
@
,因为它会抑制错误消息。另外,确定您使用的是
POST
还是
GET
。默认的表单方法是
GET
,但您的PHP需要
POST
。可能需要删除
@mail
中的
@
,因为它会抑制错误消息。另外,确定您使用的是
POST
还是
GET
。默认的表单方法是
GET
,但您的PHP需要
POST
。可能需要删除
@mail
中的
@
,因为它会抑制错误消息。另外,确定您使用的是
POST
还是
GET
。默认的表单方法是
GET
,但您的PHP需要
POST
。我添加了此方法,但在填写表单后,表单再次重定向到空页面:OMG!,您没有在表单中设置输入字段名称。请在问题中更新您的修订代码。最好得到错误。php文件的扩展名是什么?i、 e..php或.html?请看这个[张贴。这可能会对您有所帮助。我添加了这个,但在填写表单再次重定向到空页:OMG!之后,您没有在表单中设置输入字段名称。请更新您的问题中的修订代码。最好得到错误。您的php文件的扩展名是什么?即.php或.html?请查看此[张贴。这可能会对您有所帮助。我添加了这个,但在填写表单再次重定向到空页:OMG!之后,您没有在表单中设置输入字段名称。请更新您的问题中的修订代码。最好得到错误。您的php文件的扩展名是什么?即.php或.html?请查看此[post.这可能会对您有所帮助。我添加了这个,但在填写表单再次重定向到空页:OMG!之后,您没有在表单中设置输入字段名称。请更新问题中的修订代码。最好得到错误。您的php文件的扩展名是什么?即.php或.html?请参阅此[post.这可能会对您有所帮助。