我的phpMailer不工作


my phpMailer not working

hi我的phpmailer在执行mailtest.php 时产生以下结果

无法发送消息。Mailer错误:SMTP连接()失败。https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

我在这个论坛上已经讨论了很多关于phpmailer的问题,但没有一个对我有好处。

我的mailtest.php

     <?php
       require ("/phpmailer/PHPMailerAutoload.php");
       require ("/phpmailer/class.phpmailer.php");
       $mail = new PHPMailer;
       //$mail->SMTPDebug = 3;                               // Enable verbose debug output
       $mail->isSMTP();                                      // Set mailer to use SMTP
       $mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
       $mail->SMTPAuth = true;                               // Enable SMTP authentication
       $mail->Username = 'thethih@gmail.com';                 // SMTP username
       $mail->Password = 'password.';                           // SMTP password
       $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
       $mail->Port = 587;                                    // TCP port to connect to
       $mail->setFrom('from@example.com', 'Mailer');
       $mail->addAddress('thethih@gmail.com', 'Joe User');     // Add a recipient
       $mail->addAddress('thethih@yahoo.com');               // Name is optional
       $mail->addReplyTo('info@example.com', 'Information');
       $mail->addCC('cc@example.com');
       $mail->addBCC('bcc@example.com');

       $mail->isHTML(true);                                  // Set email format to HTML
       $mail->Subject = 'Here is the subject';
       $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
       $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
       if(!$mail->send()) {
         echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
        } else {
        echo 'Message has been sent';
        }
     ?>

任何帮助都将不胜感激。。并且它在localhost中。

在GitHub上,PHPMailer说"兼容PHP 5.0及更高版本",但事实可能并非如此。

尝试将您的PHP版本更改为5.5,看看这是否解决了问题。您可以通过转到控制面板并单击"PHP配置"来更改您的PHP版本。