douxidang9092 2017-02-07 07:33
浏览 55

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

<?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;
    }

}
}

?>

I am using Github library for php email. when I var_dump($mail) ; its showing all the data in the array. now, this code is showing error: "SMTP connect() failed"

  • 写回答

2条回答 默认 最新

  • dongpao5127 2017-02-07 10:40
    关注

    Just I checked up with your code no error in that. you've to enable 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;
        }
    
    
    
    ?>
    

    sample test mail

    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器