在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!"; 

     
?>

解决方案 »

  1.   

    telnet smtp.gmail.com 465也可以通
      

  2.   

    用163的SMTP(大写).163.com发送没有问题
      

  3.   

    我帮你调查了一下,最新phpmailer是支持ssl的,但是PHP也要支持SSLphp.ini里加载openssl就可以了。
    extension=php_openssl.dll
      

  4.   


    我的PHP服务器是国外的,请问这个php.ini在哪里配置啊?
      

  5.   


    我在本地用XAMPP架的PHP服务器,改了PHP.INI文件,加入了你说的那行。还是报同样的错。=====PS:我的国外服务器上,没有修改这个php.ini时,用同样的程序测试,gmail收到过一次这个程序发过去的邮件,只是后来就一直报错SMTP服务器无法连接
      

  6.   

    会不会是空间商做了限制呢?我在本地测试,用163的邮箱可以发邮件;用GMAIL的也是显示这个错误,开启PHPMAILER的调试模式显示:
    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.
      

  7.   

    Unable to find the socket transport 'ssl' - did you forget to enable it when you configured PHP?  
    该错误表明PHP不支持openssl,解决方案:windows下,在php.ini中打开opensll扩展,并将php目录下的libeay32.dll和ssleay32.dll两个库拷贝到system32下;linux下,重新编译php,编译时加上参数--enable-ssl(具体参看configure的help)
      

  8.   

    看了一下服务器的配置,openssl是打开的:openssl
    OpenSSL support  enabled
    OpenSSL Version  OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008 
      

  9.   

    SMTP -> ERROR: Failed to connect to server: Connection refused (111)