首页 > 解决方案 > 在 codeigniter 上发送电子邮件失败且没有错误

问题描述

在过去的几个小时里,我试图理解为什么我的脚本没有发送电子邮件。

在生成电子邮件内容的最后,我使用此代码发送它

if ($this->email->send()) 
{
            //all is fine
}
else
{ 
//we have a problem 
}

每次所有的想法似乎都正常时,电子邮件地址、内容等在任何情况下都不会返回失败的 send() 命令。

它会导致什么或我如何才能更接近问题?

在我的服务器日志文件中,我也看不到一些想法。

希望有人有想法...

有没有办法输出所有当前的电子邮件设置?

标签: codeigniter

解决方案


试试这个它通过本地主机为我工作

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());
    }

}

推荐阅读