PHP 邮件程序错误:无法发送邮件。邮件程序错误:SMTP 连接()失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27487745/
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: Message could not be sent.Mailer Error: SMTP connect() failed
提问by sjagr
Here is my code:
这是我的代码:
require 'phpmailertesting/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'send.one.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'myemailhidden'; // SMTP username
$mail->Password = 'mypasswordhidden'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
$mail->From = 'myemailhidden';
$mail->FromName = 'My Name';
$mail->addAddress('[email protected]'); // Name is optional
$mail->addCC('[email protected]');
$mail->addBCC('[email protected]');
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$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.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
I have tried changing the port and the type of secure connection to "TSL" and "SSL" and nothing. Ive looked at the answers already and none of them solve it. Any answers? Thanks
我曾尝试将端口和安全连接类型更改为“TSL”和“SSL”,但什么也没有。我已经看过答案了,但没有一个能解决它。任何答案?谢谢
I enabled the SMTP debugger and this is what it said "Connection: opening to ssl://send.one.com:465, t=300, opt=array ( ) 2014-12-15 15:46:40 SMTP ERROR: Failed to connect to server: Connection timed out (110) 2014-12-15 15:46:40 SMTP connect() failed"
我启用了 SMTP 调试器,这就是它所说的“连接:打开到 ssl://send.one.com:465, t=300, opt=array () 2014-12-15 15:46:40 SMTP ERROR:无法连接到服务器:连接超时 (110) 2014-12-15 15:46:40 SMTP connect() failed"
回答by sjagr
Your hosting company, one.com, blocks outgoing mail ports intentionally to restrict malicious PHP scripts. The send.one.com
address is meant for external mail clients such as your mobile phone, email client, etc. and not for internal mailing scripts from your website.
您的托管公司 one.com 故意阻止外发邮件端口以限制恶意 PHP 脚本。该send.one.com
地址用于外部邮件客户端,例如您的手机、电子邮件客户端等,而不是用于来自您网站的内部邮件脚本。
As per their support documentconcerning sending emails from your website, you must change the host to their internal SMTP address, mailout.one.com
- since this is an internal relay, you must also use port 25 and disable any security such as TLS or SSL. You must also disable authentication.
根据他们关于从您的网站发送电子邮件的支持文件,您必须将主机更改为他们的内部 SMTP 地址,mailout.one.com
因为这是一个内部中继,您还必须使用端口 25 并禁用任何安全性,例如 TLS 或 SSL。您还必须禁用身份验证。
Here is the correct configuration:
这是正确的配置:
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'mailout.one.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = false; // Authentication must be disabled
$mail->Username = 'myemailhidden';
$mail->Password = ''; // Leave this blank
$mail->Port = 25; // TCP port to connect to
回答by bromelio
The other solutions did not work for me; this one did:
其他解决方案对我不起作用;这个做了:
$mail->isSMTP();
$mail->Host = 'mailout.one.com';
$mail->SMTPAuth = false; // disable SMTP authentication
$mail->Username = '[your one.com-email]';
$mail->Password = '[your one.com-email password]';
$mail->SMTPSecure = ''; // leave this blank!
$mail->Port = 25;
Let me know if it helped you, too!
如果它也对您有帮助,请告诉我!
回答by user4954850
New to SO, so cant vote gold on you @sjagr
新来的,所以不能给你投票@sjagr
Had this problem, and as I use one.com, there were no biggey with the solution from @sjagr :)
有这个问题,当我使用 one.com 时,@sjagr 的解决方案没有什么大问题:)
You can try this full output in you file, and make sure to link the required docs.
你可以在你的文件中尝试这个完整的输出,并确保链接所需的文档。
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->Host = "mailout.one.com";
$mail->SMTPAuth = false;
$mail->Port = 25;
$mail->From = '[email protected]';
$mail->FromName = 'Mailer';
$mail->addAddress('[email protected]');
$mail->addReplyTo('[email protected]', 'Information');
$mail->addBCC('[email protected]');
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body = 'hejehej';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
//echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent, ja e fan inte tom';
} ?>