I have an html form which uses php to send the form data in an email to an external mail server. My code is this(variables changed to protect the innoicent):
我有一个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;
}
}
But I'm getting this output after submitting the form and going to the php page:
但我在提交表单并进入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
It looks like everything is fine to me (but then again, I'm a newbie to php) with the exception of the "Mail not Sent" at the end. Does anyone know why the mail isn't being sent? Based on my very limited knowledge, it seems that the external smtp server isn't relaying - but what do I know. Thanks for any help!
看起来一切对我来说都很好(但话说回来,我是php的新手),除了最后的“邮件没有发送”。有人知道为什么邮件没有被发送吗?基于我非常有限的知识,外部smtp服务器似乎并没有传递——但是我知道什么呢?感谢任何帮助!
1 个解决方案
#1
0
The remote host that you are trying to relay the messages through (74.84.86.134) reverses to spamfilter.coralville.platinum-corp.com. I assume that this is the MX for the domain that you are trying to send to, (otherwise you probably wouldn't have gotten as far as you did with the SMTP session). Notwithstanding, it seems that this remote host is accepting messages from your PHP application, but then deciding after receipt of the message that you are not a legitimate mailer, and hence the 'mail not sent' message.
您试图将消息传递到的远程主机(74.84.86.134)向spamfilter.coralville.platinum-corp.com返回。我假设这是您要发送到的域的MX(否则,您可能不会像您在SMTP会话中所做的那样)。尽管如此,这个远程主机似乎接受了来自您的PHP应用程序的消息,但是在收到消息后决定您不是一个合法的邮件发送者,因此“邮件没有发送”消息。
To check mail sent from your application has a glaring problem that would cause other mail servers to think it's spam, try sending a message from your application to check-auth@verifier.port25.com. This service will do a bunch of checks, and you'll get a report back with ton of information, such whether or not your server's DNS forwards and reverses correctly, whether your server's IP is on any black lists, if you have a problem with your SPF records, etc.
要检查从应用程序发送的邮件有一个明显的问题,这会导致其他邮件服务器认为它是垃圾邮件,试着从您的应用程序发送一条消息到checkauth@verifier.port25.com。这个服务会做一大堆检查,你会得到一份有大量信息的报告,不管你的服务器的DNS是否正确,你的服务器的IP是否在黑名单上,如果你的SPF记录有问题,等等。
Or, a simpler solution might be to just relay these outgoing messages through a well-known SMTP relay, such as smtp.gmail.com, SendGrid, etc.
或者,一个更简单的解决方案可能是通过一个著名的SMTP中继(如SMTP .gmail.com、SendGrid等)来传递这些传出消息。
#1
0
The remote host that you are trying to relay the messages through (74.84.86.134) reverses to spamfilter.coralville.platinum-corp.com. I assume that this is the MX for the domain that you are trying to send to, (otherwise you probably wouldn't have gotten as far as you did with the SMTP session). Notwithstanding, it seems that this remote host is accepting messages from your PHP application, but then deciding after receipt of the message that you are not a legitimate mailer, and hence the 'mail not sent' message.
您试图将消息传递到的远程主机(74.84.86.134)向spamfilter.coralville.platinum-corp.com返回。我假设这是您要发送到的域的MX(否则,您可能不会像您在SMTP会话中所做的那样)。尽管如此,这个远程主机似乎接受了来自您的PHP应用程序的消息,但是在收到消息后决定您不是一个合法的邮件发送者,因此“邮件没有发送”消息。
To check mail sent from your application has a glaring problem that would cause other mail servers to think it's spam, try sending a message from your application to check-auth@verifier.port25.com. This service will do a bunch of checks, and you'll get a report back with ton of information, such whether or not your server's DNS forwards and reverses correctly, whether your server's IP is on any black lists, if you have a problem with your SPF records, etc.
要检查从应用程序发送的邮件有一个明显的问题,这会导致其他邮件服务器认为它是垃圾邮件,试着从您的应用程序发送一条消息到checkauth@verifier.port25.com。这个服务会做一大堆检查,你会得到一份有大量信息的报告,不管你的服务器的DNS是否正确,你的服务器的IP是否在黑名单上,如果你的SPF记录有问题,等等。
Or, a simpler solution might be to just relay these outgoing messages through a well-known SMTP relay, such as smtp.gmail.com, SendGrid, etc.
或者,一个更简单的解决方案可能是通过一个著名的SMTP中继(如SMTP .gmail.com、SendGrid等)来传递这些传出消息。