1

I was successfully using Mandrill to send mail from my CodeIgniter site, with this config :

$config['mailtype'] = "html";
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.mandrillapp.com';
$config['smtp_user'] = 'user';
$config['smtp_pass'] = 'password';
$config['smtp_port'] = '587';
$this->email->initialize($config);

But Mandrill doesn't want to do transactionnal email, so I need to migrate to SparkPost.
Here are their directives : https://support.sparkpost.com/customer/en/portal/articles/1988470-smtp-connection-problems

I tried this config :

$config['mailtype'] = "html";
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.sparkpostmail.com';
$config['smtp_user'] = 'user';
$config['smtp_pass'] = 'password';
$config['smtp_port'] = '587';
$this->email->initialize($config);

But no mail where send, with no error. So I tried to add "tls" in the host :

$config['smtp_host'] = 'tls://smtp.sparkpostmail.com';

And I get this error :

Message: fsockopen(): SSL operation failed with code 1. OpenSSL Error messages:
error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number
Filename: libraries/Email.php
Line Number: 1950

I got the same error on port 2525.

Here is my openssl section in phpinfo on my local MAMP server :

OpenSSL support enabled
OpenSSL Library Version OpenSSL 0.9.8zg 14
July 2015 OpenSSL Header Version OpenSSL 0.9.8r 8 Feb 2011

But I have the same error on my Debian server, with phpinfo :

OpenSSL support enabled
OpenSSL Library Version OpenSSL 1.0.1e 11 Feb 2013
OpenSSL Header Version OpenSSL 1.0.1e 11 Feb 2013
Openssl default config /usr/lib/ssl/openssl.cnf

Any clue ?

Thanks a lot.

Grokify
  • 15,092
  • 6
  • 60
  • 81
Matthieu
  • 563
  • 1
  • 7
  • 25
  • I would say you need version 1.2 or even v3. Check [this](http://stackoverflow.com/questions/29627991/1408f10bssl-routinesssl3-get-recordwrong-version-number-call-on-indy) q/a. – Tpojka Apr 06 '16 at 12:31

1 Answers1

6

I was close:

SparkPost needs TLS and not SSL. It has to be setted in the parameters, and not in the server url, so that it use STARTTLS. And, last thing, I needed to change the default newline value. So here is the good config:

$config['mailtype'] = "html";
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.sparkpostmail.com';
$config['smtp_user'] = 'user';
$config['smtp_pass'] = 'password';
$config['smtp_crypto'] = 'tls';
$config['smtp_port'] = '587';
$condig['crlf'] = "\r\n";
$config['newline'] = "\r\n";
Grokify
  • 15,092
  • 6
  • 60
  • 81
Matthieu
  • 563
  • 1
  • 7
  • 25
  • Sorry, was this an invoice app? I have the exact same issue when migrating from mandrill to sparkpost. The above fix is basically what I already have, and it's still not working here ... Any other tricks? – suncat100 Apr 27 '16 at 20:38
  • This worked for me: `$this->email->set_newline("\r\n");`. For some reason, the config values for setting that weren't applying. – suncat100 Apr 28 '16 at 06:10
  • Thanks! spent hours trying to debug this, and your solution worked. – Brian Glaz Apr 18 '17 at 19:02