简体   繁体   中英

PHPMailer error: SMTP -> ERROR: Failed to connect to server

I try to google all the morning and i think i need Stackoverflow now!

I wrote a simple script to send a mail (from hotmail to gmail) but i get this error:

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. (10060)SMTP Connect() failed. 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:

sendmail_from - MY PROPER MAIL (hotmail)

sendmail_path - no value

SMTP - localhost

smtp_port - 25

Thank you!!

I believe port 25 is blocked on smtp.live.com. I cannot connect to smtp.live.com:25 from here either. Try using port 587 instead, with 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...!

  1. Edit your php.ini from your installed php folder
  2. Search for extension=php_openssl.dll
  3. The initial will look like this ;extension=php_openssl.dll
  4. Remove the ';' and it will look like this extension=php_openssl.dll
  5. If you can't find the extension=php_openssl.dll , add this line extension=php_openssl.dll .
  6. Then restart your Xampp or LAMP or APACHE server (depends upon which of these you're using).

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.
Using port 80 worked for me

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM