邮件无法发送.Mailer错误:SMTP错误:无法连接到SMTP主机

时间:2017-08-03 04:31:51

标签: email

    <?php
    require 'PHPMailerAutoload.php';



    $mail = new PHPMailer;

    //  $mail->SMTPDebug = 2;                               // 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 = 'eportalforresidency@gmail.com';                 // SMTP username
    $mail->Password = '##RESIDENCY##';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 25;                                    // TCP port to connect to
    $mail->SMTPSecure = 'ssl';
    $mail->setFrom('eportalforresidency@gmail.com', 'naimish golakiya');
    //$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
    $mail->addAddress('eportalforresidency@gmail.com');               // Name is optional
    $mail->addReplyTo('eportalforresidency@gmail.com', 'Information');
    //$mail->addCC('cc@example.com');
    //$mail->addBCC('bcc@example.com');

    //$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
    $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';
    }

    ?>

我试图通过phpmailer发送邮件,但它没有工作任何人都可以请求help.i已从gitub下载te phpmaile我也试图解决这个错误ingg在stackoverflow中提到的amsweres但仍然无法正常工作。< / p>

1 个答案:

答案 0 :(得分:0)

将端口号更新为587.此外,这些是假凭证吗?