简体   繁体   中英

codeigniter email subject line removes spaces with “_”

I use codeigniter to send some emails. Everything works fine except subject line. I am creating custom subject line like this

$mailSubject = "Customer Query | " . $bookingID . " | " . $requestID;

and use it like this

$this->email->subject($mailSubject);

But when I receive the email, the subject line looks like

Customer_Query_|_6223871_|_92

Instead I need it like

Customer Query | 6223871 | 92

This is my Function

> public function sendEmail($data) {
>         $config = Array(
>             'protocol' => 'smtp',
>             'smtp_host' => 'ssl://sub5.mail.xxxxx.com',
>             'smtp_port' => 465,
>             'smtp_user' => 'account@xxxxx.com',
>             'smtp_pass' => 'xxxxx',
>             'mailtype' => 'html',
>             'charset' => 'iso-8859-1',
>             'wordwrap' => TRUE
>         ); //set the basic configurations
> 
>         $bookingID = $data['booking_id'];
>         $requestID = $data['requestID'];
>         
>         $productCategory = "";
>         if($data['regarding'] == 1){
>             $productCategory = "Flights";
>         }else if($data['regarding'] == 2){
>             $productCategory = "Hotels";
>         }else if($data['regarding'] == 3){
>             $productCategory = "Visa Services";
>         }else if($data['regarding'] == 4){
>             $productCategory = "Travel Insurance";
>         }
>         
>         $queryType = "";
>         if($data['request_type'] == 1){
>             $queryType = "General";
>         }else if($data['request_type'] == 2){
>             $queryType = "Feedback";
>         }else if($data['request_type'] == 3){
>             $queryType = "Complain";
>         }else if($data['request_type'] == 4){
>             $queryType = "Flight Inquiry";
>         }else if($data['request_type'] == 5){
>             $queryType = "Hotel Inquiry";
>         }else if($data['request_type'] == 6){
>             $queryType = "Refund";
>         }else if($data['request_type'] == 7){
>             $queryType = "Cancellation";
>         }else if($data['request_type'] == 8){
>             $queryType = "Re-Scheduling";
>         }else if($data['request_type'] == 9){
>             $queryType = "E-ticket";
>         }else if($data['request_type'] == 10){
>             $queryType = "Invoice";
>         }else if($data['request_type'] == 11){
>             $queryType = "Visa Request";
>         }else if($data['request_type'] == 12){
>             $queryType = "Travel Insurance Request";
>         }else if($data['request_type'] == 13){
>             $queryType = "Date Change";
>         }
> 
>         $comments = $data['comments'];
>         $fname = $data['fname'];
>         $lname = $data['lname'];
>         $cusEmail = $data['email'];
>         $mobileNo = $data['contact_no'];
>         $subject = $data['subject'];
>         
>         $toEmail = "";
>         if($productCategory == 2){
>             $toEmail = "hotels@xxxxx.com";
>         }else{
>             $toEmail = "flights@xxxxx.com";
>         }
> 
>         $mailSubject = "Customer Query | " . $bookingID . " | " . $requestID;
> 
>         //prepare the message
>         $message = '<center><p><u>Customer Query</u></p></center>
>                     <p>Customer Query - '.$productCategory.' - '.$queryType.' </p>
>                     <br/>
>                     <p><b><u>Booking Details</u></b></p>
>                     <br/>
>                     <p>Product Category : '.$productCategory.'</p> 
>                     <p>Query Type : '.$queryType.' </p> 
>                     <p>Booking ID : '.$bookingID.'</p>
>                     <p>Subject : '.$subject.'</p> 
>                     <p>Comments : </p>
>                     <p><b>'.$comments.'</b></p>
>                     <br/>
>                     <p><b><u>Passenger Details</u></b></p>
>                     <br/>
>                     <p>First Name : '.$fname.'</p>
>                     <p>Last Name : '.$lname.'</p>
>                     <p>Email : '.$cusEmail.'</p>
>                     <p>Mobile No : '.$mobileNo.'</p>'; //end the message
>                         
>         //mail sending details
>         $this->load->library('email', $config);
>         $this->email->set_crlf("\r\n");
>         $this->email->from($cusEmail, $fname.' '.$lname);
>         $this->email->to('eranga.p@xxx.lk');
>         $this->email->subject($mailSubject);
>         $this->email->message($message);
> 
>         if ($this->email->send()) {//send mail and check weather it is sent successfully 
>             return TRUE;
>         } else {
>             return FALSE; //returns false if email not sent
>         }
>     }

Please try using below config params

         $config = Array(
         'protocol' => 'smtp',
         'smtp_host' => 'ssl://sub5.mail.xxxxx.com',
         'smtp_port' => 465,
         'smtp_user' => 'account@xxxxx.com',
         'smtp_pass' => 'xxxxx',
         'mailtype' => 'html',
         'charset' => 'iso-8859-1',
         'wordwrap' => TRUE,
         'remove_space' => FALSE
        ); //set the basic configurations

Set your

$config['mailtype'] ='html';

Then

$mailSubject = "Customer&nbsp;Query&nbsp;|&nbsp;".$bookingID."&nbsp;|&nbsp;".$requestID;//$nbsp; is space it is replace because your mailtype is html

$this->email->subject($mailSubject);

Replace $this->load->library('email', $config);

With

$this->load->library('email');
$this->email->initialize($config);

I found the reason for the problem. It's only happening in my mail server. For other mail servers it weren't happen. Even in outlook also it is fine. I am really sorry for wasting your valuable time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM