dongwupei7803 2016-01-22 17:54
浏览 221

PHPMailer Smtp连接失败。 连接超时(110)

date_default_timezone_set('Etc/UTC');
require 'phpmailer/PHPMailerAutoload.php'; //Create a new PHPMailer     instance

$mail = new PHPMailer;

//Tell PHPMailer to use SMTP

$mail->IsSMTP();

//Enable SMTP debugging

// 0 = off (for production use)

// 1 = client messages

// 2 = client and server messages

$mail->SMTPDebug = 2;

//Ask for HTML-friendly debug output

$mail->Debugoutput = 'html';

//Set the hostname of the mail server

$mail->Host = 'smtp.gmail.com';

// use

// $mail->Host = gethostbyname('smtp.gmail.com');

// if your network does not support SMTP over IPv6

//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission

$mail->Port = 587;

//Set the encryption system to use - ssl (deprecated) or tls

$mail->SMTPSecure = 'tls';

//Whether to use SMTP authentication

$mail->SMTPAuth = true;

//Username to use for SMTP authentication - use full email address for gmail

$mail->Username = "username@gmail.com";

//Password to use for SMTP authentication

$mail->Password = "mypassword";

//Set who the message is to be sent from

$mail->setFrom('username@gmail.com', 'User');

//Set an alternative reply-to address


//Set who the message is to be sent to

$mail->addAddress($email,$name);

//Set the subject line

$mail->Subject = 'Subject';

//Read an HTML message body from an external file, convert referenced images to embedded,

//convert HTML into a basic plain-text alternative body

$body = "body";

$mail->msgHTML($body);

//Replace the plain text body with one created manually

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

//Attach an image file

//$mail->addAttachment('images/phpmailer_mini.png');

//send the message, check for errors

if (!$mail->send()) {

echo "Mailer Error: " . $mail->ErrorInfo;

} else {

echo "Message sent!";

I tried with ports 465 and 587. No access to php.ini file and also tried setting timeout limit. No go. openssl is enabled.

Checked with:

<?php echo (extension_loaded('openssl')?'SSL loaded':'SSL not loaded')."
"; ?>

I always get the same error:

SMTP ERROR: Failed to connect to server: Connection timed out (110) SMTP connect() failed. Mailer Error: SMTP connect() failed

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏