Error in mail content using SMTP in codeigniter
Actually, my mail is sent with HTML
tags and it is showing the HTML
tags which is not correct.
Setting the mail type to HTML
works for me:
$email_setting = array('mailtype'=>'html');
$this->email->initialize($email_setting);
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Johny</td><td>10th</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://mail.example.com',
'smtp_port' => 465,
'smtp_user' => 'noreply@example.com',
'smtp_pass' => 'example@123',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_mailtype("html");
$this->email->set_newline("\r\n");
$this->email->from('noreply@example.com', 'example');
$this->email->to('example@example.in');
$this->email->subject('Enquiry');
$this->email->message($message);
Can you please try with this code, B'z I can able to send HTML email with this code.
$configemail = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com', //mail.webconsort.com
'smtp_port' => 465, //5074
'smtp_user' => 'XXXXXXXX@gmail.com', //tororide@webconsort.com
'smtp_pass' => 'XXXXXXXX', //'T0r0r1d3'
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$CI =& get_instance();
$CI->load->library('email', $configemail);
$CI->email->initialize($configemail);
$CI->email->set_newline("\r\n");
$CI->email->from($from, $fromName);
$CI->email->to($to);
$CI->email->subject($subject);
$CI->email->message($body);
if ($attachments != null && !empty($attachments)){
foreach($attachments as $a){
$CI->email->attach($a);
}
}
try{
$CI->email->send();
return true;
}
catch (Exception $e){
//var_dump($e);
}
U will try it!! it's working for mine after showing many errors it's 100% working.
$subject = 'New message.';
$config = Array(
'protocol' => 'sendmail',
'smtp_host' => 'Your smtp host',
'smtp_port' => 465,
'smtp_user' => 'webmail',
'smtp_pass' => 'webmail pass',
'smtp_timeout' => '4',
'mailtype' => 'html',
'charset' => 'utf-8',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->set_header('MIME-Version', '1.0; charset=utf-8');
$this->email->set_header('Content-type', 'text/html');
$this->email->from('from mail address', 'Company name ');
$data = array(
'message'=> $this->input->post('message')
);
$this->email->to($toEmail);
$this->email->subject($subject);
$body = $this->load->view('email/sendmail.php',$data,TRUE);
$this->email->message($body);
$this->email->send();
Gmail prevent access of your account. You need some changes on your gmail :-
Step : 1
Some apps and devices use less secure sign-in technology, which makes your account more vulnerable. You can turn off access for these apps, which we recommend, or turn on access if you want to use them despite the risks.
Turn on less secure app
Step : 2
Enable IMAP Status
Enable POP Status
Enable IMAP and POP Status
Use it like this.. it works great for me.
$this->load->library('email');
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->from($fromemail);
$this->email->to($toemail);
$this->email->subject('Subject');
$this->email->message($html);
$success=$this->email->send();