I have problem when i filter data befor sent email. Mail is not sent i try Gmail
and Yahoo
but not delivered. This my code work perfect on sub-domain but on main doman not working and that is intresting.
Check my code:
$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
Here is dump of $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
)
)
If i manual set email and subject in mail()
function that was successfull sent to gmail and yahoo.
I also try to escape and trim email and subject before pass to mail
function but again not work. This headers
is okay and work on sub-domain like i say
What can be problem here ?