Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPMailer timeout o some server

Tags:

php

phpmailer

from yesterday I'm desperately trying to run a very simple e-mail script with PHPMailer, latest version.

The most absurd thing is that the same script on two servers does not work, but on another it does.

This is my attempt (from PHPMailer examples):

date_default_timezone_set('Etc/UTC');

require '../PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->isSMTP();

$mail->SMTPDebug = 3;

$mail->Debugoutput = 'html';

$mail->Host = "smtp.live.com";

$mail->Port = 587;

$mail->SMTPAuth = true;

$mail->Username = "[email protected]";

$mail->Password = "xxxxx";

$mail->setFrom('[email protected]', 'First Last');

$mail->addReplyTo('[email protected]', 'First Last');

$mail->addAddress('[email protected]', 'John Doe');

$mail->Subject = 'PHPMailer SMTP test';

$mail->Body = 'Test';

$mail->AltBody = 'This is a plain-text message body';

//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}

Output debug:

2017-06-08 08:43:55 Connection: opening to smtp.live.com:587, timeout=300, options=array ()

2017-06-08 08:44:58 Connection failed. Error #2: stream_socket_client(): unable to connect to smtp.live.com:587 (Connection timed out) [/home/public_html/work/PHPMailer/class.smtp.php line 292]

2017-06-08 08:44:58 SMTP ERROR: Failed to connect to server: Connection timed out (110)

SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

I think it depends on the configuration of the server. Which parameter do I have to look at?

Thanks in advance

like image 341
Andrea Avatar asked Feb 16 '26 21:02

Andrea


1 Answers

No Need To Used: $mail->isSMTP();

Comment This ... $mail->isSMTP();

<?php

//error_reporting(E_ALL);
error_reporting(E_STRICT);
date_default_timezone_set('America/Toronto');

require '../PHPMailerAutoload.php';
require_once('../class.phpmailer.php');

$mail = new PHPMailer;
//$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = "smtp.live.com";
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = "[email protected]";
$mail->Password = "xxxxx";
$mail->setFrom('[email protected]', 'First Last');
$mail->addReplyTo('[email protected]', 'First Last');
$mail->addAddress('[email protected]', 'John Doe');
$mail->Subject = 'PHPMailer SMTP test';
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; 

$body = file_get_contents('test.html');
$body = eregi_replace("[\]",'',$body);
$mail->MsgHTML($body);

//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}

?>

$mail->Timeout =   60; // set the timeout (seconds)
$mail->SMTPKeepAlive = true; // don't close the connection between messages
like image 76
RïshïKêsh Kümar Avatar answered Feb 19 '26 10:02

RïshïKêsh Kümar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!