试图让我的邮件表单工作 [英] Trying to get my mail form to work

查看:71
本文介绍了试图让我的邮件表单工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你们不介意检查它,我需要另外一双眼睛。出于某种原因,我没有收到邮件。此代码在以前的站点中有效,但由于某些原因不在此处。然后,我从未在本地测试过它。我通常在实时服务器之前测试过。可能是吗?



If you guys don't mind checking it out, I need another pair of eyes. For some reason, I'm not getting the mail. This code worked in previous sites, but not here for some reason. Then again, I never tested it locally. I usually tested before from a live server. Could that be it?

<?php
if(isset($_POST['email'])) {
     
    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "lotusms@outlook.com";
    $email_subject = "Your email subject line";
     
     
    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['full_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.');       
    }
     
    $full_name = $_POST['full_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,$full_name)) {
    $error_message .= 'The First 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 .= "Full Name: ".clean_string($full_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); 
header('location: http://localhost:8079/museum/html/home.php'); 
die();
?>
 
<!-- include your own success html here -->

Thank you for contacting us. We will be in touch with you very soon.
 
<?php
}
?>

推荐答案

_POST [' email'])){

// 编辑2根据需要使用
_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED


email_to = lotusms@outlook.com;
email_to = "lotusms@outlook.com";


email_subject = 您的电子邮件主题行;


函数死亡(
email_subject = "Your email subject line"; function died(


这篇关于试图让我的邮件表单工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆