在CMD里ping一下GMAIL的SMTP服务器可以通,可是在网页里面做的发送email的程序,却总是报错:
SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.
咋回事呢:
<?php
include("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$body = "TEST_TEST";
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "[email protected]"; // GMAIL username
$mail->Password = "xxx"; // GMAIL password
$mail->From = "[email protected]";
$mail->FromName = "xxx";
$mail->Subject = "subject 111";
//$mail->Body = "Hi,<br>This is the HTML BODY<br>"; //HTML Body
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML($body);
$mail->AddAddress("[email protected]", "xxx");
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.
咋回事呢:
<?php
include("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$body = "TEST_TEST";
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "[email protected]"; // GMAIL username
$mail->Password = "xxx"; // GMAIL password
$mail->From = "[email protected]";
$mail->FromName = "xxx";
$mail->Subject = "subject 111";
//$mail->Body = "Hi,<br>This is the HTML BODY<br>"; //HTML Body
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML($body);
$mail->AddAddress("[email protected]", "xxx");
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
extension=php_openssl.dll
我的PHP服务器是国外的,请问这个php.ini在哪里配置啊?
我在本地用XAMPP架的PHP服务器,改了PHP.INI文件,加入了你说的那行。还是报同样的错。=====PS:我的国外服务器上,没有修改这个php.ini时,用同样的程序测试,gmail收到过一次这个程序发过去的邮件,只是后来就一直报错SMTP服务器无法连接
SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (32)
SMTP Error: Could not connect to SMTP host. Fail to send.This error occurs because: SMTP Error: Could not connect to SMTP host.
该错误表明PHP不支持openssl,解决方案:windows下,在php.ini中打开opensll扩展,并将php目录下的libeay32.dll和ssleay32.dll两个库拷贝到system32下;linux下,重新编译php,编译时加上参数--enable-ssl(具体参看configure的help)
OpenSSL support enabled
OpenSSL Version OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008