如何使用codeigniter解决此电子邮件问题的此错误?

时间:2018-02-13 03:02:14

标签: php codeigniter email

我有这样的问题。我想从我的网络应用程序发送邮件,所以我把它放在我的控制器中。

$from_email = "tharuwan40@gmail.com";
$to_email = "warimali94@gmail.com";

//Load email library
$this->load->library('email');
$this->email->from($from_email, 'Info');
$this->email->to($to_email);
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();

这个web应用程序仍在localhost上运行。我在网上尝试了很多这样的例子,并且已经在堆栈溢出中发布了太多。但是我的邮件上没有任何东西。电子邮件没有发送。我怎么能解决这个问题?

1 个答案:

答案 0 :(得分:0)

创建配置数组

 $config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'xxx@gmail.com',// your mail name
    'smtp_pass' => '*****',
    'mailtype'  => 'html', 
    'charset'   => 'iso-8859-1'
    'wordwrap' => TRUE
);

然后

  $this->load->library('email', $config);

  $this->email->from('mygmail@gmail.com', 'myname');//your mail address and name
  $this->email->to('target@gmail.com'); //receiver mail

  $this->email->subject('testing');
  $this->email->message($message);

  if($this->email->send()) //sending mail
  {
     echo 'Mail sent';
  }
  else
  { 
     print_r($this->email->print_debugger(), true);
  }

sendmail.ini中的配置

路径[xampp文件夹] \ sendmail \ sendmail.ini

配置

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=myemail@gmail.com
auth_password=yourgmailpassword
force_sender=myemail@gmail.com

打开php.ini配置文件并搜索[mail function]

sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

重新启动服务器

Non-Programmers Beta