SMTP error with CodeIgniter and SparkPost
<p>I use the email library to send mail using SMTP.</p>

<p>I was using Mandrill, and all was working fine.</p>

<p>I now use SparkPost, and I have irregular error. CI Library returns blank error once in a while. The exact same mail can work ten times and fail one.</p>

<p>My config :</p>

<pre><code>$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.sparkpostmail.com';
$config['smtp_user'] = '****';
$config['smtp_pass'] = '****';
$config['smtp_port'] = '587';
$config['smtp_crypto'] = 'tls';
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
$config['useragent'] = "BioCRM";
$config['wordwrap'] = FALSE;
$config['mailtype'] = "html";
$this-&gt;email-&gt;initialize($config);
</code></pre>

<p>Here are examples of errors I get with <code>print_debugger()</code></p>

<pre><code>&gt; Example 1:  
&gt; hello:  
&gt; The following SMTP error was encountered:   
&gt; starttls: 220 2.0.0 smtp.sparkpostmail.com ESMTP ecelerity 4.2.21.55447 r(Core:4.2.21.2) Thu, 09 Jun 2016 05:46:19 +0000  
&gt;The following SMTP error was encountered:   
&gt;Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.  

&gt;Example 2:  
&gt;hello: 220 2.0.0 smtp.sparkpostmail.com ESMTP ecelerity 4.2.21.55447 r(Core:4.2.21.2) Wed, 08 Jun 2016 14:08:44 +0000  
&gt;The following SMTP error was encountered: 220 2.0.0 smtp.sparkpostmail.com &gt;ESMTP ecelerity 4.2.21.55447 r(Core:4.2.21.2) Wed, 08 Jun 2016 14:08:44 +0000  
&gt;  
&gt;starttls: 250-momentum4.platform1.us-west-2.aws.cl.messagesystems.com says EHLO to 89.31.151.18:39185  
&gt; 250-ENHANCEDSTATUSCODES  
&gt; 250-8BITMIME  
&gt; 250-AUTH=LOGIN PLAIN  
&gt; 250-AUTH LOGIN PLAIN  
&gt; 250-PIPELINING  
&gt; 250 STARTTLS  
&gt; The following SMTP error was encountered: 250-momentum4.platform1.us-west-2.aws.cl.messagesystems.com says EHLO to 89.31.151.18:39185  
&gt; 250-ENHANCEDSTATUSCODES  
&gt; 250-8BITMIME  
&gt; 250-AUTH=LOGIN PLAIN  
&gt; 250-AUTH LOGIN PLAIN  
&gt; 250-PIPELINING  
&gt; 250 STARTTLS  
&gt; The following SMTP error was encountered: .0.0 continue  


&gt;Example 3:  
&gt;hello:   
&gt;The following SMTP error was encountered: 
&gt;starttls:  
&gt;The following SMTP error was encountered:  
&gt;The following SMTP error was encountered: .0.0 smtp.sparkpostmail.com ESMTP ecelerity 4.2.21.55447 r(Core:4.2.21.2) Wed, 08 Jun 2016 12:59:08 +0000  
</code></pre>

<p>As I get those errors only with Sparkpost, I asked them, and here is their answer :</p>

<blockquote>
  <p>The errors you’ve pasted are regular parts of the SMTP conversion. For example 1:</p>
  
  <p>“starttls: 220 2.0.0 smtp.sparkpostmail.com ESMTP ecelerity 4.2.21.55447 r(Core:4.2.21.2) Thu, 09 Jun 2016 05:46:19 +0000”</p>
  
  <p>Start TLS is a banner advertise to let people know we accept TLS connections. 220 is a proper code and means it’s ready to accept.<br>
  Smtp.sparkpostmail.com is the hostname of the server you’ve connected to.
  ESMTP is the protocol that is being used<br>
  Ecelerity 4.2.21.55447 r(Core:4.2.21.2) is the name and version number of the service that is handling this connection and the SMTP conversation, which is broadcasted when a connection is made. 
  (And of course, the time stamp.)</p>
  
  <p>This, however, seems like an error on your application: “Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.”</p>
  
  <p>For example 2, the response is similar, but the placement is odd. We don’t send a EHLO more than once so likely your application did not like the EHLO and reported the error after the other status codes were sent. “.0.0 continue” looks like a truncated part of the SMTP conversation, which should look more like this</p>
  
  <p>data<br>
  354 3.0.0 continue.  finished with "\r\n.\r\n"</p>
  
  <p>I'm not sure your application is interpreting those as errors, as they're all standard parts of the SMTP conversation. Since there are so many different jumps, it's certainly possible that your application is timing out or packets could be dropped between jumps. I would check to make sure if there are any packets dropped in the conversation (as that may be why you application is not recognizing the lines) and if not, why your application is not recognizing parts of the SMTP conversation. Thank you. </p>
</blockquote>

<p>Does it mean something to one of you ?</p>

<p>Thank you very much</p>