Asked 7 years ago
11 May 2017
Views 2249
pratik

pratik posted

email subject not sending properly in CodeIgniter

doing email functionality for the forget password in CodeIgniter
and i found a strange probelm.
when i get mail on subject it add some extra character which i did not add at subject.



following code i do for send e mail in codeignitor .

$config=array(

      'charset'=>'utf-8',

      'wordwrap'=> TRUE,

      'mailtype' => 'html'

      );

     $config['newline'] = "\r\n";
     $config['crlf']    = "\n";

     $sub ='Reset password';
     $this->email->initialize($config);
      $this->email->to($data->email);
     $this->email->from('Info@example.com','Example');
     $this->email->subject($sub);
      
     $encode=base64_encode($data->id."_".time());
     $link = base_url()."home/reset/".$encode;
     $this->email->message("Please click on below link to reset password.<br />".$link);
     $this->email->set_crlf( "\r\n" );
     
     $this->email->send();
     


i write there only Reset Password in subject line but it not sending proper subject.
Rasi

Rasi
answered Nov 30 '-1 00:00

i found same problem with one of the my website with codeignitor
it automatically embed special character in subject of the mail in codeignitor
i solved special character embedding issue by removing some code from "system\libraries"

email.php

find the public function subject($subject)
and it should be like this

public function subject($subject)
 {
  $subject = $this->_prep_q_encoding($subject);
  $this->_set_header('Subject', $subject);
  return $this;
 }

in above function subject in email.php pls comment first line $subject = $this->_prep_q_encoding($subject); , it will solve the error

so final code will be

public function subject($subject)
 {
 
  $this->_set_header('Subject', $subject);
  return $this;
 }


i know core lib hack is not good but i found this solution after trying many thing . i choose as my last option to do
its not good way to change or modify core libraries to any framework . -  
May 12 '17 05:49
Thanks .but it solved my problem , thumbs up to you - pratik  
May 12 '17 05:50
Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

it should be problem regarding encoding . so you can change is there any addition encoding applying it or not
Post Answer