使用 PHPMailer 通过 SMTP 发送电子邮件
我正在尝试使用 PHPMailer 发送 SMTP 电子邮件,但我不断收到此错误消息,有什么想法如何摆脱它吗?
我正在尝试通过端口 465 上的 SSL 进行连接。
SMTP -> FROM SERVER:
SMTP -> FROM SERVER:
SMTP -> ERROR: EHLO not accepted from server:
Notice: fputs() [function.fputs]: send of 18 bytes failed with errno=32 Roura přerušena (SIGPIPE) in /home/www/amazonek.cz/subdomains/library/PHPMailer_v5.1/class.smtp.php on line 494
SMTP -> FROM SERVER:
SMTP -> ERROR: HELO not accepted from server:
Notice: fputs() [function.fputs]: send of 12 bytes failed with errno=32 Roura přerušena (SIGPIPE) in /home/www/amazonek.cz/subdomains/library/PHPMailer_v5.1/class.smtp.php on line 212
SMTP -> ERROR: AUTH not accepted from server:
SMTP Error: Could not authenticate.
我的代码:
require_once('../library/PHPMailer_v5.1/class.phpmailer.php');
try{
$mail = new PHPMailer(true);
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = SMTP_SERVER;
$mail->Port = SMTP_PORT;
$mail->Username = SMTP_USERNAME;
$mail->Password = SMTP_PASSWORD;
$mail->SMTPDebug = 2;
$mail->SetFrom(MAIL_ORDERS_ADDRESS, MAIL_ORDERS_NAME);
$mail->Subject = 'AMAZONEK.cz - objednávka číslo '.$_SESSION['orderId'];
$mail->MsgHTML('<b>Ahoj</b>');
$mail->AddAddress($_SESSION['user']['email'], $_SESSION['user']['name'].' '.$_SESSION['user']['surname']);
$mail->AddBCC(MAIL_ORDERS_ADDRESS, MAIL_ORDERS_NAME);
if(!$mail->Send()) throw new Exception($mail->ErrorInfo);
}
catch(Exception $e){
echo $e->getMessage();
}
常量定义:
define('SMTP_SERVER', 'smtp.ebola.cz');
define('SMTP_PORT', 465);
define('SMTP_USERNAME', '[email protected]');
define('SMTP_PASSWORD', '***CENSORED***');
define('MAIL_ORDERS_ADDRESS', '[email protected]');
define('MAIL_ORDERS_NAME', 'My Name');
有什么想法吗?
I'm trying to send SMTP e-mails using PHPMailer, but I keep getting this error message, any ideas how to get rid of it?
I'm trying to connect via SSL on port 465.
SMTP -> FROM SERVER:
SMTP -> FROM SERVER:
SMTP -> ERROR: EHLO not accepted from server:
Notice: fputs() [function.fputs]: send of 18 bytes failed with errno=32 Roura přerušena (SIGPIPE) in /home/www/amazonek.cz/subdomains/library/PHPMailer_v5.1/class.smtp.php on line 494
SMTP -> FROM SERVER:
SMTP -> ERROR: HELO not accepted from server:
Notice: fputs() [function.fputs]: send of 12 bytes failed with errno=32 Roura přerušena (SIGPIPE) in /home/www/amazonek.cz/subdomains/library/PHPMailer_v5.1/class.smtp.php on line 212
SMTP -> ERROR: AUTH not accepted from server:
SMTP Error: Could not authenticate.
My code:
require_once('../library/PHPMailer_v5.1/class.phpmailer.php');
try{
$mail = new PHPMailer(true);
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = SMTP_SERVER;
$mail->Port = SMTP_PORT;
$mail->Username = SMTP_USERNAME;
$mail->Password = SMTP_PASSWORD;
$mail->SMTPDebug = 2;
$mail->SetFrom(MAIL_ORDERS_ADDRESS, MAIL_ORDERS_NAME);
$mail->Subject = 'AMAZONEK.cz - objednávka číslo '.$_SESSION['orderId'];
$mail->MsgHTML('<b>Ahoj</b>');
$mail->AddAddress($_SESSION['user']['email'], $_SESSION['user']['name'].' '.$_SESSION['user']['surname']);
$mail->AddBCC(MAIL_ORDERS_ADDRESS, MAIL_ORDERS_NAME);
if(!$mail->Send()) throw new Exception($mail->ErrorInfo);
}
catch(Exception $e){
echo $e->getMessage();
}
Constants definition:
define('SMTP_SERVER', 'smtp.ebola.cz');
define('SMTP_PORT', 465);
define('SMTP_USERNAME', '[email protected]');
define('SMTP_PASSWORD', '***CENSORED***');
define('MAIL_ORDERS_ADDRESS', '[email protected]');
define('MAIL_ORDERS_NAME', 'My Name');
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
带有 php 流套接字的简单 smtp 客户端,带有 tls/ssl smtp STARTTLS 命令:
https://github.com/breakermind/PhpMimeParser/blob/master/PhpSmtpSslSocketClient。 php
与 gmail.com 一起使用并进行身份验证:
Simple smtp client with php stream socket with tls/ssl smtp STARTTLS command:
https://github.com/breakermind/PhpMimeParser/blob/master/PhpSmtpSslSocketClient.php
works with gmail.com with authenticate:
使用 one.com 作为 SMTP 端口 465 不起作用。我可以在 phpmailer 中使用此配置:
Using one.com as SMTP port 465 wasn't working. I could using this configuration in phpmailer:
我在大约一个小时内遇到了非常类似的问题,直到我弄清楚出了什么问题。我的问题是,我使用了SSL,而不是ssl。检查代码中区分大小写。 AlexV 引导我找到了问题的根源。 helo/ehlo 的东西似乎无关紧要。
I had very similar problem for something like an hour, until I figured out what went wrong. My problem was, that I used SSL, instead of ssl. Check is case sensitive in the code. AlexV guided me to the source of the problem. That helo/ehlo -stuff seems irrelevant.
这是尝试使用不使用 SSL 的客户端连接到 SSL 服务的典型情况
毫无疑问,无法启动 SMTP 对话
身份验证不是一个选项。
phpmailer 不执行隐式 SSL(又名连接时的 TLS、SMTPS)
如果没有重写 smtp.class.php 以包含对其的支持,就无法执行您所要求的操作。
请改用带有显式 SSL(又名 TLS、STARTTLS)的端口 587。
that's typical of trying to connect to a SSL service with a client that's not using SSL
no suprise there having failed to start an SMTP conversation
authentigation is not an option,.
phpmailer doesn't do implicit SSL (aka TLS on connect, SMTPS)
Short of rewriting smtp.class.php to include support for it there it no way to do what you ask.
Use port 587 with explicit SSL (aka TLS, STARTTLS) instead.
是的,您需要 OpenSSL 才能正常工作。我的备份测试站点可以工作,但我的实时服务器却不能。不同之处?实时服务器在 PHP 配置中没有 OpenSSL。
Yes, you need OpenSSL to work correctly. My backup testing site worked, my live server didn't. Difference? Live server didn't have OpenSSL within PHP configuration.
这可能看起来像是盲目尝试,但如果 SMTP 需要 SSL,请确保 PHP 已符合 OpenSSL。
要检查使用
phpinfo()
希望它有帮助!
This may seem like a shot in the dark but make sure PHP has been complied with OpenSSL if SMTP requires SSL.
To check use
phpinfo()
Hope it helps!
尝试端口 25 而不是 456。
我在使用端口 456 时遇到了同样的错误,并将其更改为 25 对我有用。
try port 25 instead of 456.
I got the same error when using port 456, and changing it to 25 worked for me.
尝试通过该 SMTP 服务器手动/从交互式邮件程序(例如 Mozilla Thunderbird)发送电子邮件。从错误来看,服务器似乎不会接受您的凭据。该端口上运行的是 SMTP 还是 SSL+SMTP?您似乎没有在您发布的代码中使用安全连接,并且我不确定 PHPMailer 是否确实支持 SSL+SMTP。
(谷歌搜索 SMTP 服务器主机名的第一个结果: http://podpora.ebola.cz/idx.php/0/006/article/Strucny-technicky-popis-nastaveni-sluzeb.html似乎在说“SMTPs邮件发送:安全SSL连接,端口:465”。)
看来 PHPMailer 确实支持 SSL;至少来自这个。因此,您需要将其更改
为:
Try to send an e-mail through that SMTP server manually/from an interactive mailer (e.g. Mozilla Thunderbird). From the errors, it seems the server won't accept your credentials. Is that SMTP running on the port, or is it SSL+SMTP? You don't seem to be using secure connection in the code you've posted, and I'm not sure if PHPMailer actually supports SSL+SMTP.
(First result of googling your SMTP server's hostname: http://podpora.ebola.cz/idx.php/0/006/article/Strucny-technicky-popis-nastaveni-sluzeb.html seems to say "SMTPs mail sending: secure SSL connection,port: 465" . )
It looks like PHPMailer does support SSL; at least from this. So, you'll need to change this:
into this:
据我所知,您的代码一切正常。你的错误是:
这意味着 SMTP 服务器拒绝您发送的凭据。确保主机、端口、用户名和密码正确。
如果您想使用 STARTTLS,请尝试添加:
如果您想使用 SMTPS (SSL),请尝试添加:
请记住:
也许这个例子 可以提供帮助(GMail 安全 SMTP)。
[来源]
As far as I can see everything is right with your code. Your error is:
Which means that the credentials you've sending are rejected by the SMTP server. Make sure the host, port, username and password are good.
If you want to use STARTTLS, try adding:
If you want to use SMTPS (SSL), try adding:
Keep in mind that:
Maybe this example can help (GMail secure SMTP).
[Source]