codeigniter email displays HTML tags in email - codeigniter-2

I have a email sending code in codeigniter. I am able to send email but the HTML displays tags in the email. I have used mailtype as HTML. But it still does not work. This is my email function.
public function email_send($to_email,$subject,$message,$attach)
{
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'dsouzaj184#gmail.com';
$config['smtp_pass'] = 'abcd#1234';
$config['charset'] = 'UTF-8';
$config['smtp_crypto'] = 'ssl';
$config['priority'] = 1;
//$config['newline'] = "\r\n";
$config['mailtype'] = 'html'; // or html
$config['validation'] = TRUE; // bool whether to validate email or not
$config['crlf'] = '\r\n';
$config['newline'] = '\r\n';
$this->load->library('email',$config);
$this->email->clear(true);
//$this->email->initialize($config);
$this->email->set_mailtype("html");
$this->email->set_header('Content-Type', 'text/html');
//$this->email->set_newline('\r\n');
$this->email->from('dsouzaj184#gmail.com', 'Global Admin');
$this->email->to($to_email);
$this->email->subject($subject);
$this->email->message($message);
// return $to_email;
if($attach != '') {
$this->email->attach($attach);
}
if($this->email->send()) {
$this->email->clear(true);
return 1;
} else {
//print_r($this->email->print_debugger());
return 0;
}
}

Add wordwrap in config array as true
$config['wordwrap'] = TRUE;
and if it wont solve your problem than change
$this->load->library('email',$config);
$this->email->clear(true);
//$this->email->initialize($config);
$this->email->set_mailtype("html");
$this->email->set_header('Content-Type', 'text/html');
//$this->email->set_newline('\r\n');
to
$this->load->library('email');
$this->email->initialize($config);
$this->email->set_newline('\r\n');
$this->email->clear();

Related

SMTP Mail Not Send in Codeigniter

In Config.php File I have changes
$config['protocol']='smtp';
$config['smtp_hostname'] = "ssl://smtp.zoho.com";
$config['smtp_crypto'] = 'tls';
$config['smtp_username'] = "aaaa";
$config['smtp_password'] = "xxx";
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['newline'] = "\r\n";
But MAil Not Send.
enter image description here

Email not send using Codelgniter

I want to send an email to the user who is verified by the Admin. When the admin clicks on verify button in DB the status of a user is changed and email sends to a user, status can change but the email not send.
AdminController:
if($this->AdminModel->updateUser($id , $status)){
$user_message = "hello";
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'kshahroz699#gmail.com';
$config['smtp_pass'] = 'password';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'text'; // or html
$config['validation'] = TRUE;
$this->email->initialize($config);
$this->email->from('kshahroz699#gmail.com', 'Model Hunt Inquiry');
$this->email->to($email);
$this->email->subject('Model Hunt Inquiry Form');
$this->email->message($user_message);
if($this->email->send()) {
echo " Successfully send";
}else{
echo "Not Send";
}
AdminModel:
function updateUser($id, $data){
$this->db->where('id',$id);
return $this->db->update('mh_users',$data);
}
Route:
$route['verifyUserEmail/(:any)/(:any)'] = 'Admin/verifyEmail/$1/$2';
Admin Model
function updateUser($id, $data){
$this->db->where('id',$id);
return $this->db->update('mh_users',$data);
}
My Controller
$this->load->library('email');
if($this->AdminModel->updateUser($id , $status)){
$from = 'no-reply#test.com';
$to = 'test#gmail.com';
$message1 = 'Hello Test';
$config = array();
$config['useragent'] = "CodeIgniter";
$config['mailpath'] = "/usr/bin/sendmail"; // or "/usr/sbin/sendmail"
$config['protocol'] = "smtp";
$config['smtp_host'] = "localhost";
$config['smtp_port'] = "25";
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$this->email->from($from, 'Test');
$this->email->to($to);
$this->email->subject('Test');
$this->email->message($message1);
$this->email->set_mailtype('html');
if($this->email->send()){
$message=array("1","Mail Sent Successfully");
}else{
$message=array("0",$this->db->_error_message());
}
}
$this->session->set_flashdata('message', $message);

Send mpdf output as attachment email file with PHPMailer in Codeigniter

I have pdf file created with mpdf library and I want to send the output file as attachment in email with PHPMailer. I have tried this code but still not working. The attachment is missing but the email is successfully sent.
This is my code in controller :
public function pdf_file()
{
$this->load->library('m_pdf');
$this->data['title']="MY PDF TITLE 1.";
$this->data['description']="Test PDF File";
$html=$this->load->view('frontend/pdf_output',$this->data, true);
$pdfFilePath = "the_pdf_output.pdf";
$pdf = $this->m_pdf->load();
$pdf->SetProtection(array('copy'), '123456', '123456', 128);
$pdf->SetVisibility('screenonly');
$pdf->WriteHTML($html,2);
//$pdf->Output($pdfFilePath, "D");
$content = $pdf->Output('', 'S');
$content = chunk_split(base64_encode($content));
$subject = "PDF File";
$message = $this->load->view('frontend/pdf_output',$this->data,TRUE);
$from = "aaa#yahoo.com";
$to = 'xxx#gmail.com';
$cc = null;
$attachment = $content;
$sender = "Administrator";
$site_url = site_url();
if ($site_url == 'http://localhost/mysite/')
{
$this->load->view('frontend/email',$data);
}
else
{
$this->booking_model->send_email($subject,$message,$from,$to,$cc,$attachment,$sender);
}
}
This is my PHPMailer configuration :
function send_email($subject,$message,$from,$to,$cc,$attachment,$sender)
{
$this->load->library('PHPMailerAutoload');
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->Host = "mail.host.com";
$mail->IsHTML(true);
$mail->Port = 26;
$mail->SMTPAuth = true;
//$mail->SMTPSecure = 'ssl';
$mail->Username = "aaa#domain.com";
$mail->Password = "123456";
$mail->setFrom($from, $sender);
if (count($cc) > 1)
{
for ($i=1; $i <= count($cc); $i++)
{
$mail->addCC($cc[$i], $sender);
}
}
if (!empty($attachment))
{
$mail->addAttachment($attachment);
}
$mail->addAddress($to);
$mail->Subject = $subject;
$mail->msgHTML($message);
//send the message, check for errors
if (!$mail->send()) {
// failed
} else {
// success
}
}
Anyone know to send the pdf attachment on email ? Please help.

Codeigniter: Sending two emails from different senders

I am trying to send two emails, each from a different sender. The problem is that the second email is sent from the sender of the first email.
Codeigniter is ignoring the $this->email->from of the second email
$this->load->library('email');
$html="some text";
// send email
$config['mailtype'] = 'html';
$config['protocol'] = "smtp";
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_user'] = 'user#gmail.com';
$config['smtp_pass'] = 'password';
$config['smtp_port'] = '465';
$config['newline'] = "\r\n";
$this->email->initialize($config);
$this->email->from('myemail#gmail.com', '');
$this->email->to("someemail#site.com");
$this->email->subject("The subject");
$this->email->message($html);
if($this->email->send()) {
}
$this->email->clear();
$config1['mailtype'] = 'html';
$this->email->initialize($config1);
$this->email->from('thesecondemail#www.com', 'The test');
$this->email->to("user#eee.com");
$html="Some other text";
$this->email->subject("hello some text");
$this->email->message($html);
if($this->email->send()) {
}

CodeIgniter and phpmailer

I'm using CodeIgniter 3.0.3 and PHPMailer (https://github.com/ivantcholakov/codeigniter-phpmailer).
I have a problem with the configuration because it does not send e-mails.
This is my config file:
<?php defined('BASEPATH') OR exit('No direct script access allowed.');
$config['useragent'] = 'PHPMailer'; // Mail engine switcher: 'CodeIgniter' or 'PHPMailer'
$config['protocol'] = 'smtp'; // 'mail', 'sendmail', or 'smtp'
$config['mailpath'] = '/usr/sbin/sendmail';
$config['smtp_host'] = 'mail.skins4points.pl';
$config['smtp_user'] = 'noreply#skins4points.pl';
$config['smtp_pass'] = 'mypass';
$config['smtp_port'] = 587;
$config['smtp_timeout'] = 5; // (in seconds)
$config['smtp_crypto'] = ''; // '' or 'tls' or 'ssl'
$config['smtp_debug'] = 0; // PHPMailer's SMTP debug info level: 0 = off, 1 = commands, 2 = commands and data, 3 = as 2 plus connection status, 4 = low level data output.
$config['wordwrap'] = true;
$config['wrapchars'] = 76;
$config['mailtype'] = 'html'; // 'text' or 'html'
$config['charset'] = null; // 'UTF-8', 'ISO-8859-15', ...; NULL (preferable) means config_item('charset'), i.e. the character set of the site.
$config['validate'] = true;
$config['priority'] = 3; // 1, 2, 3, 4, 5; on PHPMailer useragent NULL is a possible option, it means that X-priority header is not set at all, see https://github.com/PHPMailer/PHPMailer/issues/449
$config['crlf'] = "\n"; // "\r\n" or "\n" or "\r"
$config['newline'] = "\n"; // "\r\n" or "\n" or "\r"
$config['bcc_batch_mode'] = false;
$config['bcc_batch_size'] = 200;
$config['encoding'] = '8bit'; // The body encoding. For CodeIgniter: '8bit' or '7bit'. For PHPMailer: '8bit', '7bit', 'binary', 'base64', or 'quoted-printable'.
I am using the email account you set up with hekko.pl
Here sample configuration mail client: http://www.pomoc.hekko.pl/content/28/53/pl/konfiguracja-poczty-w-mozilla-thunderbird.html
I'd guess that smtp_crypto needs to be tls if you're talking to port 587.

Resources