-
valencia Newbie

-
Posts: 8
Threads: 2
Joined: Dec 2014
Reputation:
0
hi all,
I'm sending email with CI but I can't get html tags as I want.
here is my code
this is my Model folder
PHP Code: ##forgot password send email public function forgot_pass($email) { $this->form_validation->set_rules('email_f_f_pass','email','required|valid_email|is_unique[users.email]|trim'); if($this->form_validation->run() == TRUE && !empty($email) ){ $config = Array( 'protocol' => 'sendmail', 'mailtype' => 'html', 'charset' => 'utf-8', 'wordwrap' => TRUE
);
$message = $this->load->view('admin/ad_pages/send_email', '', true); $this->load->library('email', $config); $this->email->set_newline("\r\n"); $this->email->from(@$email); $this->email->to('[email protected]'); $this->email->subject('send email to costomer'); $this->email->message($message); if($this->email->send()){ echo'<div style="position:relative; top:50px; width:330px; margin:0 auto;" class="alert alert-dismissable alert-danger"> <button type="button" class="close" data-dismiss="alert">x</button> <strong>success!</strong> Please, check your email for new password !!! </div>'; $this->output->set_header('refresh:3; url='.base_url().'admin/admin_pages/login'); }else{ show_error($this->email->print_debugger()); } }else{ $this->load->view('admin/ad_pages/forgot_pass'); } }
and this my success mesage php page
PHP Code: <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <h1>success</h1> <p>your message send <b>successfuly!!</b></p> </body> </html>
in received email I'm getting back the page as it is likethis
Code: <!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h1>success</h1>
<p>your message send <b>successfuly!!</b></p>
</body>
</html>
instead something like tthis
Code: [b]success[/b] big like h1 expected
and
Code: your message send [b]successfuly!![/b]
what did I make wrong,? something with header content type maybe? Can someone help me with this?
-
Avenirer Senior Member
   
-
Posts: 419
Threads: 15
Joined: Oct 2014
Reputation:
21
(12-23-2014, 03:27 PM)valencia Wrote: hi all,
I'm sending email with CI but I can't get html tags as I want.
here is my code
this is my Model folder
PHP Code: ##forgot password send email public function forgot_pass($email) { $this->form_validation->set_rules('email_f_f_pass','email','required|valid_email|is_unique[users.email]|trim'); if($this->form_validation->run() == TRUE && !empty($email) ){ $config = Array( 'protocol' => 'sendmail', 'mailtype' => 'html', 'charset' => 'utf-8', 'wordwrap' => TRUE
);
$message = $this->load->view('admin/ad_pages/send_email', '', true); $this->load->library('email', $config); $this->email->set_newline("\r\n"); $this->email->from(@$email); $this->email->to('[email protected]'); $this->email->subject('send email to costomer'); $this->email->message($message); if($this->email->send()){ echo'<div style="position:relative; top:50px; width:330px; margin:0 auto;" class="alert alert-dismissable alert-danger"> <button type="button" class="close" data-dismiss="alert">x</button> <strong>success!</strong> Please, check your email for new password !!! </div>'; $this->output->set_header('refresh:3; url='.base_url().'admin/admin_pages/login'); }else{ show_error($this->email->print_debugger()); } }else{ $this->load->view('admin/ad_pages/forgot_pass'); } }
and this my success mesage php page
PHP Code: <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <h1>success</h1> <p>your message send <b>successfuly!!</b></p> </body> </html>
in received email I'm getting back the page as it is likethis
Code: <!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h1>success</h1>
<p>your message send <b>successfuly!!</b></p>
</body>
</html>
instead something like tthis
Code: [b]success[/b] big like h1 expected
and
Code: your message send [b]successfuly!![/b]
what did I make wrong,? something with header content type maybe? Can someone help me with this?
I don't think you can define an array like:
$config = Array(
'protocol' => 'sendmail',
'mailtype' => 'html',
'charset' => 'utf-8',
'wordwrap' => TRUE
);
You define array by using array() and not Array().
-
valencia Newbie

-
Posts: 8
Threads: 2
Joined: Dec 2014
Reputation:
0
(12-23-2014, 05:13 PM)Avenirer Wrote: (12-23-2014, 03:27 PM)valencia Wrote: hi all,
I'm sending email with CI but I can't get html tags as I want.
here is my code
this is my Model folder
PHP Code: ##forgot password send email public function forgot_pass($email) { $this->form_validation->set_rules('email_f_f_pass','email','required|valid_email|is_unique[users.email]|trim'); if($this->form_validation->run() == TRUE && !empty($email) ){ $config = Array( 'protocol' => 'sendmail', 'mailtype' => 'html', 'charset' => 'utf-8', 'wordwrap' => TRUE
);
$message = $this->load->view('admin/ad_pages/send_email', '', true); $this->load->library('email', $config); $this->email->set_newline("\r\n"); $this->email->from(@$email); $this->email->to('[email protected]'); $this->email->subject('send email to costomer'); $this->email->message($message); if($this->email->send()){ echo'<div style="position:relative; top:50px; width:330px; margin:0 auto;" class="alert alert-dismissable alert-danger"> <button type="button" class="close" data-dismiss="alert">x</button> <strong>success!</strong> Please, check your email for new password !!! </div>'; $this->output->set_header('refresh:3; url='.base_url().'admin/admin_pages/login'); }else{ show_error($this->email->print_debugger()); } }else{ $this->load->view('admin/ad_pages/forgot_pass'); } }
and this my success mesage php page
PHP Code: <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <h1>success</h1> <p>your message send <b>successfuly!!</b></p> </body> </html>
in received email I'm getting back the page as it is likethis
Code: <!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h1>success</h1>
<p>your message send <b>successfuly!!</b></p>
</body>
</html>
instead something like tthis
Code: [b]success[/b] big like h1 expected
and
Code: your message send [b]successfuly!![/b]
what did I make wrong,? something with header content type maybe? Can someone help me with this?
I don't think you can define an array like:
$config = Array(
'protocol' => 'sendmail',
'mailtype' => 'html',
'charset' => 'utf-8',
'wordwrap' => TRUE
);
You define array by using array() and not Array().
Thank you, that was good to find that Array(), I missed it but after i changed it I'm still receiving html as it is, there must be something else.
I even changed 'protocol' => 'sendmail', to 'protocol' => 'mail', and tryed but not success.
-
Rufnex Chuck Norris Mode - Former CI Council
   
-
Posts: 511
Threads: 7
Joined: Oct 2014
Reputation:
35
Try also
PHP Code: $this->email->set_mailtype("html");
And check if you have als an email.php in your config folder. Maye you overwrite there your settings.
-
valencia Newbie

-
Posts: 8
Threads: 2
Joined: Dec 2014
Reputation:
0
(12-24-2014, 04:09 AM)Rufnex Wrote: Try also
PHP Code: $this->email->set_mailtype("html");
And check if you have als an email.php in your config folder. Maye you overwrite there your settings.
when I'm sending mail like this, this is working så there is something with setting content type in CI, and I dont get it, I do the way CI says, but it's not working.
the way it's works
PHP Code: $to = $email; $subject = "forgotten password";
$message = " <html> <head> <title>Your Password</title> </head> <body> <h2>hi,this->username</h2> <div><p>your new password is: <b>newpassword</b></p><p>you can log in with this than you can change your password on your profile page.</p><p><a href=''>Go to login page</a></p></div> </body> </html> ";
// Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: bla bla' . "\r\n";
mail($to,$subject,$message,$headers);
here is the what I'm receiving when I try to send CI way, an I see there is text/plain - t's not text/html in contnet type
PHP Code: Subject: =?utf-8?Q?send_email_to_costomer?= To: ahmet@hotmail.com X-PHP-Originating-Script: 0:Email.php User-Agent: CodeIgniter Date: Wed, 24 Dec 2014 22:39:18 +0000 From: <rws@hotmail.com> Return-Path: <rws@hotmail.com> Reply-To: "[email protected]" <rws@hotmail.com> X-Sender: rws@hotmail.com X-Mailer: CodeIgniter X-Priority: 3 (Normal) Message-ID: <549b409610661@hotmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="B_ALT_549b40961066f"
This is a multi-part message in MIME format. Your email application may not support this format.
--B_ALT_549b40961066f Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit
success your message send successfuly!!
--B_ALT_549b40961066f Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML> <html lang=3D"en-US"> <head> <meta charset=3D"UTF-8"> <title></title> </head> <body> <h1>success</h1> <p>your message send <b>successfuly!!</b></p> </body> </html>
--B_ALT_549b40961066f--
I want to send this CI way to learn. I gave many hours to this now!!
|