Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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!!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
563 views
Welcome To Ask or Share your Answers For Others

1 Answer

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';   

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...