[英]PHP Mailer error: Message could not be sent.Mailer Error: SMTP connect() failed
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('example@example.com'); // Name is optional
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');
//$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. 我已经尝试将端口和安全连接的类型更改为“TSL”和“SSL”,什么都没有。 Ive looked at the answers already and none of them solve it.
我已经看了答案,但没有人解决它。 Any answers?
任何答案? Thanks
谢谢
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错误:无法连接到服务器:连接超时(110)2014-12-15 15:46:40 SMTP连接()失败“
Your hosting company, one.com, blocks outgoing mail ports intentionally to restrict malicious PHP scripts. 您的托管公司one.com有意阻止外发邮件端口限制恶意PHP脚本。 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. send.one.com
地址适用于外部邮件客户端,例如您的移动电话,电子邮件客户端等,而不适用于您网站的内部邮件脚本。
As per their support document concerning 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. 根据他们关于从您的网站发送电子邮件的支持文档 ,您必须将主机更改为其内部SMTP地址
mailout.one.com
- 因为这是内部中继,您还必须使用端口25并禁用任何安全性,如TLS或SSL。 You must also disable authentication. 您还必须禁用身份验证。
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
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! 如果它对你有帮助,请告诉我!
New to SO, so cant vote gold on you @sjagr SO的新手,所以不能给你@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 = 'your@domain.se';
$mail->FromName = 'Mailer';
$mail->addAddress('sendtothis@domain.se');
$mail->addReplyTo('ireply@domain.se', 'Information');
$mail->addBCC('bcc@example.com');
$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';
} ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.