PHP 邮件程序错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2227702/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP mailer error
提问by ArK
I tried to use php mailer but errors as follows.
我尝试使用 php mailer,但错误如下。
SMTP -> FROM SERVER:
SMTP -> FROM SERVER:
SMTP -> ERROR: EHLO not accepted from server:
SMTP -> FROM SERVER:
SMTP -> ERROR: HELO not accepted from server:
SMTP -> ERROR: AUTH not accepted from server:
SMTP -> NOTICE: EOF caught while checking if connectedSMTP Error: Could not authenticate. Message could not be sent.
Mailer Error: SMTP Error: Could not authenticate.
and my code
和我的代码
<?php
require("class.phpmailer.php")
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->SMTPDebug = 2;
$mail->Username = "[email protected]";
$mail->Password = "xxxxxxxx";
$mail->From = "[email protected]";
$mail->FromName = "Mailer";
$mail->AddAddress("[email protected]", "mine");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "Here is the subject"
$mail->Body = "This is the HTML message body <b>in bold!</b>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send()) {
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
回答by Ashley Schroder
I was getting this due to wrong port for SSL.
由于 SSL 端口错误,我得到了这个。
SSL = 465 TLS = 587
SSL = 465 TLS = 587
See: http://mail.google.com/support/bin/answer.py?hl=en&answer=13287
请参阅:http: //mail.google.com/support/bin/answer.py?hl=zh-CN&answer=13287
回答by fire
Some servers (especially shared hosting) will block you from using SSL with SMTP, I had the same problem once.
某些服务器(尤其是共享主机)会阻止您在 SMTP 中使用 SSL,我曾经遇到过同样的问题。
Either change host if you can, try using the default PHP mail() function or send through another mail server that does not require SSL e.g. port 25 not 465.
如果可以,请更改主机,尝试使用默认的 PHP mail() 函数或通过另一个不需要 SSL 的邮件服务器发送,例如端口 25 而不是 465。
Something like AuthSMTPwould be your best bet for an alternate mail server.
像AuthSMTP这样的东西将是替代邮件服务器的最佳选择。
回答by mana
I had the same problems, it seems that we have
to set the SMPTSecure value.
First I changed the port from 465 to 587 and added:
$mail->SMTPSecure = "tls";
and it worked :)
我遇到了同样的问题,看来我们必须设置 SMPTSecure 值。首先我将端口从 465 更改为 587 并添加:
$mail->SMTPSecure = "tls"; 它奏效了:)
回答by Tabish
If you are working in your localhost just go to the PHP Extentionand enable or check the php_opensslit will be able to access the SSL ports.
如果您在本地主机中工作,只需转到PHP 扩展并启用或检查php_openssl,它将能够访问 SSL 端口。
回答by Priyank
try this code
试试这个代码
require '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
//$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
//$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 465;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'ssl';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "[email protected]";
//Password to use for SMTP authentication
$mail->Password = "admin123";
$mail->setFrom('[email protected]', 'development'); //add sender email address.
$mail->addAddress('[email protected]', "development"); //Set who the message is to be sent to.
//Set the subject line
$mail->Subject = $response->subject;
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->Body = 'Name: '.$data['name'].'<br />Location: '.$data['location'].'<br />Email: '.$data['email'].'<br />Phone:'.$data['phone'].'<br />ailment: '.$data['ailment'].'<br />symptoms: '.$data['symptoms'];
//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.gif');
//$mail->SMTPAuth = true;
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
回答by user2309537
Had the same issue, Change port No in opencart mail setting to 587 and works fine
有同样的问题,将 opencart 邮件设置中的端口号更改为 587 并且工作正常
回答by user3231324
I use the same script for several clients and only run into this problem when deploying to Amazon EC2 cloud providers (such as Openshift).
我对多个客户端使用相同的脚本,并且仅在部署到 Amazon EC2 云提供商(例如 Openshift)时遇到此问题。
These are tried and tested settings in phpmailer: $mail->SMTPSecure = "tls"; // sets the prefix to the servier $mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server $mail->Port = 587;
这些是 phpmailer 中经过试验和测试的设置: $mail->SMTPSecure = "tls"; // 设置服务器前缀 $mail->Host = "smtp.gmail.com"; // 将 GMAIL 设置为 SMTP 服务器 $mail->Port = 587;
'but' Google blocks these services as an 'anti-spam' / political maneuver, and this has caught me out because it works locally and on most hosting providers, there is nothing much you can do when they don't accept outbound messages from your hosts DNS / IP. Accept it and move on by looking for another smtp server to route messages through.
“但是”谷歌将这些服务作为一种“反垃圾邮件”/策略来阻止,这让我很震惊,因为它在本地和大多数托管服务提供商上都有效,当他们不接受来自的出站消息时,您无能为力您的主机 DNS/IP。接受它并继续寻找另一个 smtp 服务器来路由消息。
回答by Shoban
May be because of fire wall?
可能是因为防火墙?
If you can't sign in to Google Talk, or you're receiving an error that says, Could not authenticate to server, check if you have personal firewall software installed, or if your computer is behind a proxy server that requires a username and password.
如果您无法登录 Google Talk,或者您收到一条错误消息:无法对服务器进行身份验证,请检查您是否安装了个人防火墙软件,或者您的计算机是否位于需要用户名和密码。
http://www.google.com/support/talk/bin/answer.py?hl=en&answer=30998
http://www.google.com/support/talk/bin/answer.py?hl=zh-CN&answer=30998
回答by Young
not sure but try $mail->Host = "smtp.gmail.com" =>$mail->Host = "smtp.google.com"
不确定但试试 $mail->Host = "smtp.gmail.com" =>$mail->Host = "smtp.google.com"

