简体   繁体   English

PHPMailer 错误:SMTP -> 错误:无法连接到服务器

[英]PHPMailer error: SMTP -> ERROR: Failed to connect to server

I try to google all the morning and i think i need Stackoverflow now!我整个早上都在尝试谷歌,我想我现在需要 Stackoverflow!

I wrote a simple script to send a mail (from hotmail to gmail) but i get this error:我写了一个简单的脚本来发送邮件(从 hotmail 到 gmail),但我收到了这个错误:

SMTP -> ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. SMTP -> ERROR: Failed to connect to server: 连接尝试失败,因为连接方在一段时间后没有正确响应,或者连接失败,因为连接的主机没有响应。 (10060)SMTP Connect() failed. (10060)SMTP Connect() 失败。 Error错误

This is the code:这是代码:

<?php
require_once("../includes/phpMailer/class.phpMailer.php");
require_once("../includes/phpMailer/class.smtp.php");


$to_name = "RECEIVER NAME";
$to = "RECEIVER@gmail.com";


$subject = "Mail test at " . strftime("%T", time());

$message = "This is a test message";
$message = wordwrap($message, 70);


$from_name = "MY NAME";
$from = "MY_EMAIL@hotmail.it";


$mail = new PHPMailer();

$mail->IsSMTP();
$mail->SMTPDebug  = 2;
$mail->Host = "smtp.live.com";
$mail->Port = 25;
$mail->SMTPAuth = true;
$mail->Username = "MY USERNAME (hotmail)";
$mail->Password = "MY PASSWORD (hotmail)";


$mail->FromName = $from_name;
$mail->From = $from;
$mail->AddAddress($to, $to_name);
$mail->Subject = $subject;
$mail->Body = $message;

$result = $mail->Send();

echo $result ? 'Sent' : 'Error';

?>

Another info is that not even the standard mail() function worked, and checking php info i found this:另一个信息是,甚至标准的 mail() 函数都不起作用,检查 php 信息我发现了这个:

sendmail_from - MY PROPER MAIL (hotmail) sendmail_from - 我的正确邮件(hotmail)

sendmail_path - no value sendmail_path - 没有价值

SMTP - localhost SMTP - 本地主机

smtp_port - 25 smtp_port - 25

Thank you!!谢谢!!

I believe port 25 is blocked on smtp.live.com.我相信 smtp.live.com 上的端口 25 被阻止。 I cannot connect to smtp.live.com:25 from here either.我也无法从这里连接到 smtp.live.com:25。 Try using port 587 instead, with TLS.尝试使用端口 587 和 TLS。 So, it would be:所以,它会是:

$mail->Port = 587;
$mail->SMTPSecure = 'tls';   

I found a solution for this problem, try this我找到了解决这个问题的方法,试试这个

Check whether your PHP is using openSSL extension or not...!检查您的 PHP 是否正在使用openSSL扩展...!

  1. Edit your php.ini from your installed php folder从已安装的 php 文件夹中编辑php.ini
  2. Search for extension=php_openssl.dll搜索extension=php_openssl.dll
  3. The initial will look like this ;extension=php_openssl.dll初始看起来像这样;extension=php_openssl.dll
  4. Remove the ';'去除 ';' and it will look like this extension=php_openssl.dll它看起来像这样extension=php_openssl.dll
  5. If you can't find the extension=php_openssl.dll , add this line extension=php_openssl.dll .如果找不到extension=php_openssl.dll ,请添加此行extension=php_openssl.dll
  6. Then restart your Xampp or LAMP or APACHE server (depends upon which of these you're using).然后重新启动您的 Xampp 或 LAMP 或 APACHE 服务器(取决于您使用的是哪一个)。

Hope this method shall solve your problem...希望这个方法能解决你的问题...

You may want to check the supported ports.您可能需要检查支持的端口。 For instance, my host supports smtp via ports 25, 3535 and 80.例如,我的主机通过端口 25、3535 和 80 支持 smtp。
Using port 80 worked for me使用端口 80 对我有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PHPMailer:SMTP 错误:无法连接到服务器:(0)与godaddy - PHPMailer: SMTP ERROR: Failed to connect to server: (0) with godaddy PHPMailer SMTP错误:无法连接到服务器 - PHPMailer SMTP ERROR: Failed to connect to server SMTP连接失败-phpmailer中Localhost上的PHPMailer错误 - SMTP connect failed - PHPMailer Error on Localhost in phpmailer PHPMailer可以正常运行一会儿,然后:SMTP错误:无法连接到服务器:(10060)错误:SMTP connect()失败 - PHPMailer was woking fine for a while and then: SMTP ERROR: Failed to connect to server: (10060) ERROR: SMTP connect() failed 在 CentOS 服务器上使用 reCaptcha 在 PHPmailer 上出现 SMTP 连接()失败错误 - SMTP connect() failed error on PHPmailer with reCaptcha on a CentOS server class.phpmailer.php SMTP-&gt;错误:无法连接到服务器 - class.phpmailer.php SMTP -> ERROR: Failed to connect to server PHPMailer的臭名昭著的SMTP错误:无法连接到服务器:连接超时(110)SMTP connect()失败 - PHPMailer's infamous SMTP ERROR: Failed to connect to server: Connection timed out (110) SMTP connect() failed PHPMailer,SMTP连接()失败错误与Gmail - PHPMailer, SMTP connect() failed error with Gmail PHPmailer 失败,错误:SMTP 连接()失败 - PHPmailer fails,error: SMTP connect() failed 解决 PHPMailer 错误 SMTP 连接失败 - Resolve PHPMailer Error SMTP Connect failed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM