我正在尝试在codeigniter框架中的控制器类中发送包含以下代码的电子邮件...
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('tanvir@soft-bd.com', 'tanvir@soft-bd.com');
$this->email->to('tanvir064@gmail.com');
$this->email->subject('This is an email test');
$this->email->message('It is working. Great!');
if ($this->email->send()) {
echo "Sent!";
$this->email->print_debugger();
} else {
echo "FAILED";
echo $this->email->print_debugger();
}
但显示以下错误
我的代码有什么问题?
答案 0 :(得分:0)
您可以尝试使用此代码。我正在从Gmail smtp服务器发送邮件......
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->view('upload_success','',TRUE);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('xxx@gmail.com'); // change it to yours
$this->email->to('yyy@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());
}
}
答案 1 :(得分:0)
将此代码粘贴到您的功能开始
$this->load->library('email');
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
这对你有帮助!