Codeigniter $this->email->send() 不工作,而 mail()
2022-08-31 00:09:45
我不知道为什么如果我尝试使用CI电子邮件类,它不会发送电子邮件,而如果我使用本机PHP mail()类工作。
必须注意的是,有时我收到“电子邮件已发送”,而实际上并未发送,有时我会收到错误“我的服务器未设置”。
我试图弄清楚如何设置它,但是...无。。。
控制器代码如下:
if($this->form_validation->run()){
//Set Language
$this->lang->load('site', $this->session->userdata('lang'));
//Random key
$user_valid_key = md5(uniqid());
//Prepare email
$this->load->library('email', array('mailtype' => 'html'));
$this->email->from($this->config->item('email_signup_from'), 'Wondermark.net');
$this->email->to($this->input->post('email'));
$this->email->subject($this->lang->line('email_signup_subject'));
//Format mail con %s per inserire i campi necessari
$signup_msg = sprintf($this->lang->line('email_signup_message'), $this->input->post('fname'), base_url().'main/signup_confirm/'.$user_valid_key);
$this->email->message((string)$signup_msg);
if($this->email->send()){
//TODO: load view...
echo "email sent";
}else{
$to = $this->input->post('email');
mail($to, 'test', 'Other sent option failed');
echo $this->input->post('email');
show_error($this->email->print_debugger());
}
//TODO: Add to db
}else{
// Form validation failed
}