【问题标题】:send mail from local server using xampp in php使用 php 中的 xampp 从本地服务器发送邮件
【发布时间】:2017-06-24 08:40:19
【问题描述】:
<?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 库用于 php 电子邮件。 当我 var_dump($mail) ;它显示了数组中的所有数据。 现在,此代码显示错误:“SMTP connect() failed”

【问题讨论】:

标签: php codeigniter xampp localhost


【解决方案1】:

我也遇到了这个问题,请按以下步骤操作

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

【讨论】:

    【解决方案2】:

    我刚刚检查了您的代码,没有任何错误。你必须启用https://www.google.com/settings/security/lesssecureapps

    <?php
    
    include "PHPMailer_5.2.4/class.phpmailer.php";
       $mail = new PHPMailer;
    
    
            $mail->isSMTP();                               
            $mail->Host = 'smtp.gmail.com'; 
            $mail->SMTPAuth = true;                               
            $mail->Username = 'test@gmail.com';              
            $mail->Password = 'test@12123#';  
            $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;
        }
    
    
    
    ?>
    

    【讨论】:

    猜你喜欢
    • 2013-10-08
    • 2011-03-05
    • 2013-12-18
    • 2012-08-29
    • 2011-08-19
    • 2013-01-20
    • 1970-01-01
    • 2015-05-24
    • 2011-12-10
    相关资源
    最近更新 更多