我在发送电子邮件时过滤数据时遇到问题。我尝试Gmail
和Yahoo
但未发送邮件。这个我的代码在子域上工作得很好,但主要的doman不工作,这很有意义。
检查我的代码:
$this->db->where('user_id', $userInsertid);
$this->db->update('users', $update);
$this->db->where('id','1');
$query = $this->db->get('mail_templates');
$mailtemp = $query->result_array();
$message = $mailtemp['0']['mail_message'];
$fromEmail = $mailtemp['0']['mail_from'];
$subject = $mailtemp['0']['mail_subject'];
$toEmail = $this->input->post('email');
$urls ='<a target="_blank" href="'.base_url().'register/verify/'.$tuno.'">click here</a>';
$logo=base_url().'skin/site/images/logo.png';
$message = str_replace('#name', $this->input->post('firstName'), $message);
$message = str_replace('#adminemail',$fromEmail, $message);
$message = str_replace('#username', "Msg", $message);
$message = str_replace('#password', "qwe123", $message);
$message = str_replace('#verifyurl', $urls, $message);
$message = str_replace('#logo', $logo, $message);
$message = str_replace('#sitename',"ASD", $message);
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <support@mysite.com>' . "\r\n";
$headers .= 'Cc: <support@mysite.com>' . "\r\n";
$email = filter_var($toEmail, FILTER_SANITIZE_EMAIL);
$sub = filter_var($subject, FILTER_SANITIZE_STRING);
mail($email,$sub,$message,$headers); // <-- NOT WORK
mail('myemail@gmail.com','Test Subject',$message,$headers); // <-- WORK
这是$mailtemp
Array
(
[0] => Array
(
[id] => 1
[mail_from] => support@mysite.com
[mail_subject] => User Registration
[mail_message] => <HTML tempalte>
[created_at] => 2014-09-28 15:31:23
[created_by] => 1
[modified_at] => 2016-06-04 07:10:06
[modified_by] => 1
)
)
如果我手动设置成功发送到gmail和yahoo的mail()
功能中的电子邮件和主题。
在传递给mail
函数之前,我还试图逃避并修剪电子邮件和主题,但再次无效。这个headers
没关系,就像我说的那样在子域上工作
这里有什么问题?