关于参数,要注意的只有三点
$config['newline'] = "\r\n";
我也不知道为啥不加这个就不行,坑了我大把时间自己看代码吧
//发送邮件
public function sendEmail(){
//接收前端jsonPOST
$parameter = $GLOBALS['HTTP_RAW_POST_DATA'];
$json = json_decode($parameter);
$par = array(
'ordinal' => $json->ordinal,
'account' => $json->account,
'companyName' => $json->companyName,
'address' => $json->address,
'legalRepresentative' => $json->legalRepresentative,
'representativeTel' => $json->representativeTel,
'contactMan' => $json->contactMan,
'contactPhone' => $json->contactPhone,
'email' => $json->email
);
//根据email发送邮件
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.mxhichina.com';
$config['smtp_user'] = 'xxxx@xxxxx.cn';
$config['smtp_pass'] = 'xxxxx';//密码
$config['smtp_port'] = '25';
$config['charset'] = 'utf-8';
$config['mailtype'] = 'text';
$config['smtp_timeout'] = '5';
$config['newline'] = "\r\n";
$this->load->library('email', $config);
$this->email->from('minjieapp@minjie.cn', 'TESTMAN');//发件人邮箱和名字
$this->email->to($par['email']);//收件人邮箱
$this->email->subject('This is my subject');//主题
$this->email->cc('another@another-example.com');//抄送人
$this->email->message('Hi '.$par['companyName'].' Here is the info you requested.');//邮件正文
// $this->email->send();//发送邮件
// echo $this->email->print_debugger();
// $this->response($this->email->print_debugger(), 200, null);
// return;
if($this->email->send()){
$this->response('success', 200, null);
}else{
$this->response($this->email->print_debugger(), 200, null);
}
}
以上。
Written on September 19th, 2019 by Martube