如果来自雅虎的电子邮件地址,我的php()邮件脚本不会发送电子邮件

时间:2014-08-10 13:21:57

标签: php contact-form

唯一的问题是from字段包含电子邮件 来自雅虎(example@yahoo.com)的地址,我看不到 收件箱中的电子邮件和垃圾文件夹。 这是我使用的脚本:

  <?php
  function spamcheck($field) {
    // Sanitize e-mail address
    $field=filter_var($field, FILTER_SANITIZE_EMAIL);
    // Validate e-mail address
    if(filter_var($field, FILTER_VALIDATE_EMAIL)) {
      return TRUE;
    } else {
      return FALSE;
    }
  }
    if ('POST' === $_SERVER['REQUEST_METHOD']) 
    {
    // Check if the "from" input field is filled out
    if (isset($_POST["from"])) {
      // Check if "from" email address is valid
      $mailcheck = spamcheck($_POST["from"]);
      if ($mailcheck==FALSE) {
        echo "Please enter a valid e-mail address";
      } else {
        $to = "xxxxx@xxxxxx.com";
        $from = filter_var($_POST["from"]); // sender
        $subject = $_POST["subject"];
        $message = $_POST["message"];
        // message lines should not exceed 70 characters (PHP rule), so wrap it
        $message = wordwrap($message, 70, "\r\n");
        $header='From: '.$from."\r\n";
        // send mail
        mail($to,$subject,$message,$header);
      }
    }
  }
  ?>

1 个答案:

答案 0 :(得分:0)

使用php邮件程序库(https://github.com/PHPMailer/PHPMailer)。 干杯!