簡體   English   中英

無法在 Codeigniter 中使用 PhpMailer 從 Gmail 發送郵件?

[英]could not sending mail from Gmail using PhpMailer in Codeigniter?

我正在嘗試在 codeigniter 中使用 PhpMailer 從 Gmail 帳戶發送郵件但它說一個錯誤:

無法發送郵件。郵件程序錯誤:SMTP connect() 失敗。 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';

我猜你沒有允許在 gmail 中訪問。 您需要在 Gmail 中允許訪問安全性較低的應用程序才能使用該帳戶發送電子郵件。 您可以參考此鏈接進行操作:
https://support.google.com/accounts/answer/6010255?hl=en
您還需要添加這一行:

$mail->Port = 587; 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM