使用php中的xampp从本地服务器发送邮件

时间:2017-02-07 07:33:34

标签: php codeigniter xampp localhost

<?php

class EmailModel extends CI_Model{
    public function email(){

        require 'Email Files/PHPMailerAutoload.php';


        $mail = new PHPMailer;


        $mail->isSMTP();                               
        $mail->Host = 'smtp.gmail.com'; 
        $mail->SMTPAuth = true;                               
        $mail->Username = 'Google account username';              
        $mail->Password = 'Google account Password';  
        $mail->SMTPSecure = 'ssl';
        $mail->Port = 465;  
        $mail->addAddress('abc@gmail.com');
        $mail->setFrom('abc@gmail.com');
        $mail->Subject = 'Test';
        $mail->Body    = 'Testing';

        if($mail->send()) {
            echo 'Message has been sent';

        } else {
            echo 'Message could not be sent.';
            echo 'Mailer Error: ' . $mail->ErrorInfo;
    }

}
}

?>

我正在使用Github库来发送电子邮件。 当我var_dump($ mail);它显示数组中的所有数据。 现在,此代码显示错误:&#34; SMTP connect()失败&#34;

2 个答案:

答案 0 :(得分:1)

我也有这个问题。请执行以下步骤

  • 转到myaccount.google.com
  • 点击“已连接的应用和网站”,
  • 将“允许安全性较低的应用”转为“开启”(页面底部)。

答案 1 :(得分:0)

我检查过您的代码时没有错误。您已启用https://www.google.com/settings/security/lesssecureapps

BottomSheetView

sample test mail