外部SMTP给SERVER - >客户端:250确定:排队为CA053776D18邮件未发送

时间:2015-02-03 23:48:02

标签: php email smtp external phpmailer

我有一个html表单,它使用php将电子邮件中的表单数据发送到外部邮件服务器。我的代码是这样的(变量变化以保护innoicent):

<?php

//$ckNotify = $_POST['ckNotify'];
$ckNotify = isset($_POST['ckNotify']) && $_POST['ckNotify'] ? "Please sign me up for Email Notifications" : "NO";

$ckUnsubscribe = isset($_POST['ckUnsubscribe']) && $_POST['ckUnsubscribe'] ? "Plese unsubscribe me from Email Notifications" : "Does Not Apply to this instance";

$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];

if (!empty($_POST)) //Validate first
{
    if (empty($name) || empty($visitor_email)) {
        echo "Name and email are mandatory!";
        exit;
    }
}

if (IsInjected($visitor_email)) {
    echo "Bad email value!";
    exit;
}

date_default_timezone_set('America/Chicago');

require_once 'PHPMailerAutoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
// 3 = verbose messages
$mail->SMTPDebug = 3;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "74.84.86.134";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 25;
//Whether to use SMTP authentication
$mail->SMTPAuth = false;
//Set who the message is to be sent from
$mail->setFrom('miket@extsmtp.net', 'Mike Tolliver');
//Set an alternative reply-to address
$mail->addReplyTo('miket@extsmtp.net', 'Mike Tolliver');
//Set who the message is to be sent to
$mail->addAddress('miket@extsmtp.net', 'Mike Tolliver');
//Set the subject line
$mail->Subject = 'New Form Submission';
//Get message contents from form and place in body of email as basic plain-test
$body = "Email Notifications: $ckNotify
UnSubscribe User: $ckUnsubscribe
Name: $name
Email: $visitor_email
Message: $message";
$mail->MsgHTML($body);
//Replace the plain text body with one created manually
//$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png');
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

//done - redirect to thank-you page if no errors
if (!$mail->Send()) {
    header('Location: ThankYou.html');
//echo "Mail Sent Successfully";
} else {
    echo "Mail Not Sent";
}

// Function to validate against any email injection attempts
function IsInjected($str)
{
    $injections = array(
        '(\n+)',
        '(\r+)',
        '(\t+)',
        '(%0A+)',
        '(%0D+)',
        '(%08+)',
        '(%09+)'
    );
    $inject = join('|', $injections);
    $inject = "/$inject/i";
    if (preg_match($inject, $str)) {
        return true;
    } else {
        return false;
    }
}

但是我在提交表单并进入php页面后得到了这个输出:

    2015-02-03 23:18:21 Connection: opening to 74.84.86.134:25, t=10, opt=array ( ) 
2015-02-03 23:18:21 Connection: opened 
2015-02-03 23:18:21 SERVER -> CLIENT: 220 barracuda.platinum-corp.com ESMTP (b35451cd44f584ec6f962de7068c7240) 
2015-02-03 23:18:21 CLIENT -> SERVER: EHLO www.extsmtp.net 
2015-02-03 23:18:21 SERVER -> CLIENT: 250-barracuda.platinum-corp.com Hello www.extsmtp.net [173.0.129.93], pleased to meet you 250-SIZE 100000000 250-STARTTLS 250-PIPELINING 250-8BITMIME 250 HELP 
2015-02-03 23:18:21 CLIENT -> SERVER: MAIL FROM: 
2015-02-03 23:18:21 SERVER -> CLIENT: 250 Sender OK 
2015-02-03 23:18:21 CLIENT -> SERVER: RCPT TO: 
2015-02-03 23:18:21 SERVER -> CLIENT: 250 Recipient OK 
2015-02-03 23:18:21 CLIENT -> SERVER: DATA 
2015-02-03 23:18:21 SERVER -> CLIENT: 354 Start mail input; end with . 
2015-02-03 23:18:21 CLIENT -> SERVER: Date: Tue, 3 Feb 2015 17:18:21 -0600 
2015-02-03 23:18:21 CLIENT -> SERVER: Return-Path: miket@extsmtp.net 
2015-02-03 23:18:21 CLIENT -> SERVER: To: Mike Tolliver 
2015-02-03 23:18:21 CLIENT -> SERVER: From: Mike Tolliver 
2015-02-03 23:18:21 CLIENT -> SERVER: Reply-to: Mike Tolliver 
2015-02-03 23:18:21 CLIENT -> SERVER: Subject: New Form Submission 
2015-02-03 23:18:21 CLIENT -> SERVER: Message-ID: <718f56184800b47dd0a9327e8003f4f1@www.extsmtp.net> 
2015-02-03 23:18:21 CLIENT -> SERVER: X-Priority: 3 
2015-02-03 23:18:21 CLIENT -> SERVER: X-Mailer: PHPMailer 5.2 (http://code.google.com/a/apache-extras.org/p/phpmailer/) 
2015-02-03 23:18:21 CLIENT -> SERVER: MIME-Version: 1.0 
2015-02-03 23:18:21 CLIENT -> SERVER: Content-Type: multipart/alternative; 
2015-02-03 23:18:21 CLIENT -> SERVER: boundary="b1_718f56184800b47dd0a9327e8003f4f1" 
2015-02-03 23:18:21 CLIENT -> SERVER: 
2015-02-03 23:18:21 CLIENT -> SERVER: 
2015-02-03 23:18:21 CLIENT -> SERVER: --b1_718f56184800b47dd0a9327e8003f4f1 
2015-02-03 23:18:21 CLIENT -> SERVER: Content-Type: text/plain; charset="iso-8859-1" 
2015-02-03 23:18:21 CLIENT -> SERVER: Content-Transfer-Encoding: 8bit 
2015-02-03 23:18:21 CLIENT -> SERVER: 
2015-02-03 23:18:21 CLIENT -> SERVER: To view the message, please use an HTML compatible email viewer! 
2015-02-03 23:18:21 CLIENT -> SERVER: 
2015-02-03 23:18:21 CLIENT -> SERVER: 
2015-02-03 23:18:21 CLIENT -> SERVER: --b1_718f56184800b47dd0a9327e8003f4f1 
2015-02-03 23:18:21 CLIENT -> SERVER: Content-Type: text/html; charset="iso-8859-1" 
2015-02-03 23:18:21 CLIENT -> SERVER: Content-Transfer-Encoding: 8bit 
2015-02-03 23:18:21 CLIENT -> SERVER: 
2015-02-03 23:18:21 CLIENT -> SERVER: Email Notifications: Please sign me up for Email Notifications 
2015-02-03 23:18:21 CLIENT -> SERVER: UnSubscribe User: Does Not Apply to this instance 
2015-02-03 23:18:21 CLIENT -> SERVER: Name: Joyce Small 
2015-02-03 23:18:21 CLIENT -> SERVER: Email: jsmall@somewhere.net 
2015-02-03 23:18:21 CLIENT -> SERVER: Message: Test message using external smtp settings 
2015-02-03 23:18:21 CLIENT -> SERVER: 2015-02-03 23:18:21   CLIENT -> SERVER: 
2015-02-03 23:18:21 CLIENT -> SERVER: 
2015-02-03 23:18:21 CLIENT -> SERVER: --b1_718f56184800b47dd0a9327e8003f4f1-- 
2015-02-03 23:18:21 CLIENT -> SERVER: 
2015-02-03 23:18:21 CLIENT -> SERVER: . 
2015-02-03 23:18:21 SERVER -> CLIENT: 250 Ok: queued as CA053776D18 Mail Not Sent

看起来对我来说一切都很好(但话又说回来,我是php的新手),除了&#34; Mail not Sent&#34;在末尾。有谁知道为什么邮件没有被发送?基于我非常有限的知识,似乎外部smtp服务器不是中继 - 但我知道什么。谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

您尝试通过(74.84.86.134)中继邮件的远程主机将转换为spamfilter.coralville.platinum-corp.com。我假设这是您尝试发送到的域的MX,(否则您可能不会像使用SMTP会话那样得到)。尽管如此,似乎这个远程主机正在接受来自您的PHP应用程序的消息,但是在收到消息后决定您不是合法的邮件程序,因此未发送邮件&#39;信息。

要检查从您的应用程序发送的邮件有一个明显的问题,可能导致其他邮件服务器认为它是垃圾邮件,请尝试从您的应用程序发送消息check-auth@verifier.port25.com。此服务将进行大量检查,您将收到大量信息的报告,例如您的服务器的DNS是否正确转发和撤销,无论您的服务器的IP是否已启用任何黑名单,如果你的SPF记录有问题等等。

或者,更简单的解决方案可能是通过众所周知的SMTP中继来传递这些传出消息,例如smtp.gmail.com,SendGrid等。