【问题标题】:could not sending mail from Gmail using PhpMailer in Codeigniter?无法使用 Codeigniter 中的 PhpMailer 从 Gmail 发送邮件?
【发布时间】:2016-05-21 08:00:56
【问题描述】:

我正在尝试使用 Codeigniter 中的 PhpMailer 从 Gmail 帐户发送邮件但它显示错误:

无法发送邮件。邮件程序错误:SMTP 连接()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

我在代码中做什么:

$this->load->library('MY_PHPMailer');
        $mail = new PHPMailer();
        $mail->isSMTP();
        $mail->Host = 'smtp.gmail.com';
        $mail->SMTPAuth = true;
        $mail->Username = 'xamplee@gmail.com';
        $mail->Password = '123456';
        $mail->SMTPSecure = 'tls';
        $mail->From = 'example@gmail.com';
        $mail->FromName = 'test';
        $mail->addAddress('example@gmail.com', 'MT');
        $mail->addReplyTo('example@gmail.com', 'MT');
        $mail->WordWrap = 50;
        $mail->isHTML(true);
        $mail->Subject = 'test using';
        $mail->Body = 'Hi 2';
        if (!$mail->send()) {
            echo 'Message could not be sent.';
            echo 'Mailer Error: ' . $mail->ErrorInfo;
            exit;
        }
        echo 'Message has been sent';

【问题讨论】:

标签: php codeigniter email phpmailer


【解决方案1】:

我猜你没有允许在 gmail 中访问。 您需要在 gmail 中允许访问不太安全的应用程序才能使用该帐户发送电子邮件。您可以参考此链接来执行此操作:
https://support.google.com/accounts/answer/6010255?hl=en
您还需要添加这一行:

$mail->Port = 587; 

【讨论】:

    猜你喜欢
    • 2023-03-28
    • 2015-07-09
    • 1970-01-01
    • 2014-04-28
    • 2017-11-04
    • 2013-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多