PHPMailer错误连接:打开到ssl://smtp.gmail.com:465,timeout = 300,options = array()

时间:2016-09-19 08:10:32

标签: php email ssl phpmailer

您好我正在尝试使用PHPMailer,它不能正常工作,但是错误

  

连接:打开ssl://smtp.gmail.com:465,超时= 300,options = array()

这是我的代码

     require_once('mailFiles/PHPMailerAutoload.php');
echo (extension_loaded('openssl')?'SSL loaded':'SSL not loaded')."<br/>";
                $mail = new PHPMailer();
                $mail->isSMTP();
                $mail->SMTPDebug = 4;
                $mail->Debugoutput = 'html';
                $mail->SMTPAuth = true;
                $mail->SMTPSecure = 'ssl';
    //            $mail->SMTPSecure = 'tls';
                $mail->Host = 'smtp.gmail.com';
    //            $mail->Host = gethostbyname('smtp.gmail.com');
    //            $mail->Host = 'tls://smtp.gmail.com:587';
    //            $mail->Port = 587;
                $mail->Port = 465;
                $mail->Username = "xs4arabiabahrain@gmail.com";
                $mail->Password = "mailpass";
                $mail->setFrom('mail@gmail.com', 'Firstz Last');
                $mail->addAddress('myemail@gmail.com', 'MAAGE-EMAIL User');
                $mail->IsHTML(true);

                //Set the subject line
                $mail->Subject = 'PHPMailer GMail SMTP test';
                //Read an HTML message body from an external file, convert referenced images to embedded,
                //convert HTML into a basic plain-text alternative body
                $mail->msgHTML('Hi test 123');
                //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');
                $result = $mail->send();
                if (!$result) {
                    echo ("Mailer Error: "); 
                    echo ($mail->ErrorInfo);
                } else {
                    echo ("Message sent!"); 
                }

累了 tls 仍然无法正常工作。

1 个答案:

答案 0 :(得分:0)

问题出在我使用McAfee的防病毒软件,您需要更改其设置,请按照此link更改这些设置。我希望它也可以帮助其他人。