doulian8485 2017-04-09 12:38
浏览 43

尝试使用codeIgniter发送邮件[重复]

This question already has an answer here:

I'm trying to send mail with data using but it's not sending anything and here's my function

public function sendmail($response) {
   $this->load->library('email');
$bcc="";

    $this->email->from(EMAIL_FROM_EMAIL, EMAIL_FROM_NAME);
    $this->email->to("dinacs110@gmail");

    if (!empty($bcc)) {
        $this->email->bcc($bcc);
    }

    $this->email->set_mailtype("html");
    $this->email->subject("Hello Test");
    $this->email->message("body");
    $serverList = array('localhost', '127.0.0.1');
    if (!in_array($_SERVER['HTTP_HOST'], $serverList)) {
        $this->email->send();
    }

}

I have make this update but still not sending anything

public function sendmail($response){
        require_once('phpmailer_/PHPMailerAutoload.php');

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'localhost';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'dinacs110@gmail.com';                 // SMTP username
$mail->Password = '*****';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;                                    // TCP port to connect to

$mail->setFrom('dinacs110@gmail.com', 'dinacs110@gmail.com');
$mail->addAddress('dinacs110@gmail.com', 'Joe User');     // Add a recipient
$mail->addAddress('dinacs110@gmail.com');               // Name is optional
$mail->addReplyTo('dinacs110@gmail.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');


$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}
        }

The update code just give me a message on my gmail that someone trying to hack my mail then i have make it's not secure to access the mail but still not having error or even mail !! so what's the error here ?

</div>
  • 写回答

1条回答 默认 最新

  • dongqiang5932 2017-04-09 12:51
    关注

    Because your machine doesnt have email server if you are in localhost,you can use smtp mail

    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算