通过localhost使用codeigniter库发送电子邮件 [英] Send email by using codeigniter library via localhost

查看:214
本文介绍了通过localhost使用codeigniter库发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public function sendemail(){
  $config = Array( 
  'protocol' => 'smtp', 
  'smtp_host' => 'ssl://smtp.googlemail.com', 
  'smtp_port' => 465, 
  'smtp_user' => 'email@gmail.com', 
  'smtp_pass' => 'password', ); 

  $this->load->library('email', $config); 
  $this->email->set_newline("\r\n");
  $this->email->from('email@gmail.com', 'Name');
  $this->email->to('email@yahoo.com');
  $this->email->subject(' My mail through codeigniter from localhost '); 
  $this->email->message('Hello World…');
  if (!$this->email->send()) {
    show_error($this->email->print_debugger()); }
  else {
    echo 'Your e-mail has been sent!';
  }
}   



我使用codeigniter发送错误电子邮件:

I get an error when I use codeigniter to send the email:

Message: mail() [function.mail]: Failed to connect to mailserver at 
"localhost" port 25, verify your "SMTP" and "smtp_port" setting in 
php.ini or use ini_set().

Unable to send email using PHP mail(). Your server might not be 
configured to send mail using this method.

我做错了什么?

推荐答案

请检查我的工作代码。

function sendMail()
{
    $config = Array(
  'protocol' => 'smtp',
  'smtp_host' => 'ssl://smtp.googlemail.com',
  'smtp_port' => 465,
  'smtp_user' => 'xxx@gmail.com', // change it to yours
  'smtp_pass' => 'xxx', // change it to yours
  'mailtype' => 'html',
  'charset' => 'iso-8859-1',
  'wordwrap' => TRUE
);

        $message = '';
        $this->load->library('email', $config);
      $this->email->set_newline("\r\n");
      $this->email->from('xxx@gmail.com'); // change it to yours
      $this->email->to('xxx@gmail.com');// change it to yours
      $this->email->subject('Resume from JobsBuddy for your Job posting');
      $this->email->message($message);
      if($this->email->send())
     {
      echo 'Email sent.';
     }
     else
    {
     show_error($this->email->print_debugger());
    }

}

这篇关于通过localhost使用codeigniter库发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆