2019-08-12 07:26
浏览 170

smtp connect()使用phpmailer库在PHP中失败[关闭]

I have Found Error to send mail in PHP using phpmailer Library.any one can answer this Error. Thank you.

smtp connect() failed.

require_once APPPATH.'third_party/phpmailer/class.phpmailer.php';
require_once APPPATH.'third_party/phpmailer/class.smtp.php';

    $rtn = false;
    $mail = new PHPMailer();

    $mail->SMTPDebug  = 0;
    $mail->SMTPAuth   = true;
    $mail->SMTPSecure = "tls";
    $mail->Host       = '';
    $mail->Port       = 587;
    $mail->Username   = '';
    $mail->Password   = 'mypassword';
    $mail->SMTPOptions = array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true
    $mail->SetFrom('', 'Smart Saver Support');
    $mail->AddReplyTo('', 'Smart Saver Support');
    $mail->Subject = $subject;

    $rtn = $mail->Send();
    return $rtn;
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douchongzhang9267 2019-08-12 07:36

    Hey Do you Allow less secure apps to access your Gmail account ? if you not allow less secure apps enable and Run again and see the result.

    Here is the Example:

    解决 无用
    打赏 举报
  • dongyanjing5975 2019-08-12 07:34

    It's maybe because of the wrong username and password given in SMTP authentication or SMTP port blocked in mail server firewalls.

    If you are using Gmail account, please check this link and turn off the "Allow less secure apps".

    Here is the URL:

    Then try to send email again.

    解决 无用
    打赏 举报

相关推荐 更多相似问题