• 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
send email with html tags

#1
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?
Reply

#2
(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().
Reply

#3
(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.
Reply

#4
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.

Reply

#5
(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?=
Toahmet@hotmail.com
X
-PHP-Originating-Script0:Email.php
User
-AgentCodeIgniter
Date
Wed24 Dec 2014 22:39:18 +0000
From
: <rws@hotmail.com>
Return-
Path: <rws@hotmail.com>
Reply-To"[email protected]<rws@hotmail.com>
X-Senderrws@hotmail.com
X
-MailerCodeIgniter
X
-Priority(Normal)
Message-ID: <549b409610661@hotmail.com>
Mime-Version1.0
Content
-Typemultipart/alternativeboundary="B_ALT_549b40961066f"

This is a multi-part message in MIME format.
Your email application may not support this format.

--
B_ALT_549b40961066f
Content
-Typetext/plaincharset=utf-8
Content
-Transfer-Encoding8bit

success
 your message send successfuly
!!


--
B_ALT_549b40961066f
Content
-Typetext/htmlcharset=utf-8
Content
-Transfer-Encodingquoted-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!!
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.