发送电子邮件的Php文件未正确执行

时间:2016-06-08 11:11:13

标签: php html forms email

网站来源:http://www.salefee.com/

请查看此网站。我已经制作了一个表格来输入电子邮件地址"要收到salefee故事电子书,请提交您的电子邮件ID"。此表单将重定向到名为story.php文件的php文件。这个php文件被编程为向admin发送电子邮件。

问题是,当用户点击提交按钮时,它会被重定向到网址http://www.salefee.com/story.php并显示空白页面,而我没有收到自动邮件。 我的story.php文件如下:

<?php
if ($_POST) {
  $to_email = "salefee12@gmail.com" //Recipient email, Replace with own email here


  //Sanitize input data using PHP filter_var().
   $user_trial_email   = filter_var($_POST["trial-email"], FILTER_SANITIZE_EMAIL);

  //additional php validation
 if (!filter_var($user_trial_email, FILTER_VALIDATE_EMAIL)) { //email validation
    $output = json_encode(array('type'=>'error', 'text' => 'Please enter a valid email.'));
    die($output);
  }

  //subject
  $subject = "The Story";
  $user_trial_name = "salefee12@gmail.com"
  $user_trial_phone = "1234567890"

  //email body
  $message_body = "Name   : ".$user_trial_name."\r\nEmail  : ".$user_trial_email."\r\nPhone  : ".$user_trial_phone."\r\nApp link:https://play.google.com/apps/testing/com.salefee.salefee.salefee";


  //proceed with PHP email.
  $headers = 'From: '.$user_trial_name.''."\r\n".
  'Reply-To: '.$user_trial_email.''."\r\n".
  'X-Mailer: PHP/'.phpversion();

  $send_mail = mail($to_email, $subject, $message_body, $headers);

  if (!$send_mail)
  {
    //If mail couldn't be sent output error. Check your PHP email configuration (if it ever happens)
    $output = json_encode(array('type'=>'error', 'text' => 'Could not send mail! Please check your PHP mail configuration.'));
    die($output);
  } else {
    $output = json_encode(array('type'=>'message', 'text' => 'Hi '.$user_trial_name.', Thank you for subscribing. You will soon get a link to download app.'));
    die($output);
  }
}
?>

我在html文件中的表格如下:

<!-- Mailchimp Newsletter -->
              <div class="newsletter-wrapper animateblock rtl-2 speed-1">
              <form action="story.php" method="post">
              <div class="form-group input-group input-newsletter" style="width:400px;margin: 0 auto;">
              <input class="form-control" id="trial-email" name="trial-email" type="email" required autocomplete="on" placeholder="Enter email" style="border-color:#D9534F;">
              <div class="input-group-btn">
              <button class="btn btn-danger" type="submit">click me</button>
              </div>
              </div>
              </form>
              </div>
              </div>

              <!-- End Mailchimp Newsletter -->

我在我的网站上使用了其他2种形式的类似php代码。其他2种形式工作正常(我收到邮件)。但是这个PHP代码无效。

请帮我这个代码。指导我如何调试此代码或如何在浏览器上打印消息,以便我可以理解我的代码正常运行的位置。在此先感谢。!!

0 个答案:

没有答案