SMTP 451 error: CodeIgniter Email

I believe that the problems occurs only when the SMTP server is exceptionally strict and enforces 822bis section 2.3 rule in the header of the email as well. The problem with my scenario occured when the subject of the email was too large and had to occupy two lines. I think that Codeigniter has a bug in that particular function and doesn’t end the line of the subject correctly.





How to fix the SMTP 451 error in Codeigniter :


  1. Navigate to system/libraries/Email.php
  2. Go to _prep_q_encoding function
  3. Change the following code located at line 320 from:



     if ((strlen($temp) + strlen($char)) >= $limit)
     {
$output .= $temp.$this->crlf;
$temp = '';
      }

      to :

     if ((strlen($temp) + strlen($char)) >= $limit)
     {
//$output .= $temp.$this->crlf;
$output .= $temp."\n";
$temp = '';
      }

      
     4.  Change the return of the function from:

          return $str;

     to :

          return str_replace(array("\n"), array("\r\n"), $str);


I am submit a working fix as i was content with my hack. So there you go. If you are encountering the SMTP 451 error I advise to give this hack a try and let me know if that worked out for you.

If you like this post don't forgot to leave a comment.

Chears :)
Happy coding ...

Post a Comment

Previous Post Next Post