I have CodeIgniter project running on a cPanel/centOS based host. The CodeIgniter email class (running off of phpMailer v 6.1.4) is not working on this host, but is working locally and in other environments.
-
When we run the code below on our cPanel-based host, we get an uninterpretable error from the PHPMailer debugging function:
The following SMTP error was encountered: +�W��TV���:����;�D���q�� Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
-
The weird thing is that everything was working until two days ago, and nothing was changed (to my knowledge) on the code-level.
- When we check error logs we see the following:
Severity: Warning –> stream_socket_enable_crypto(): Peer certificate
CN=*.mywebhost.com' did not match expected CN=
smtp.sendgrid.net’
/home/myenv/public_html/system/libraries/Email.php
The above leads me to believe that:
- The host is utilizing some kind of configuration (such as “FKA SMTP Tweak”) preventing us from connecting to SendGrid. (I toggled this on/off, but it didn’t seem to to anything).
- There’s some kind of SSL issue
I’ve been trying to diagnose with our host, but they have been rather unhelpful until now, so any insights would be most welcome and thanks in advance!
Please let us know if we can provide any more information and thank you in advance for your cooperation.
$config = array();
$config['useragent'] = 'PHPMailer';
$config['protocol'] = 'smtp';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['smtp_host'] = 'smtp.sendgrid.net';
$config['smtp_user'] = 'USER';
$config['smtp_pass'] = 'PASSWORD';
$config['smtp_port'] = 587;
$config['smtp_timeout'] = 5;
$config['smtp_crypto'] = 'tls';
$config['wordwrap'] = true;
$config['wrapchars'] = 76;
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['validate'] = true;
$config['priority'] = 3;
$config['crlf'] = "n";
$config['newline'] = "n";
$config['bcc_batch_mode'] = false;
$config['bcc_batch_size'] = 200;
$this->load->library('email');
$this->email->initialize($config);
$this->email->from('[email protected]', 'Your Name');
$this->email->to('[email protected]');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
show_error($this->email->print_debugger());
2
Answers
NOTE: This solution may vary, but this is what resolved my issue. (Please see @Syncro's comment, it's more precise...the 'solution' below was how I resolved things with the hosting provider in my particular case).
My hosting provider had to:
That said, I've tested SendGrid's PHP API Library and am probably going to go with that. I think PHPMailer is a great solution, but in some cases (such as was mine), certain hosting providers might interfere with it.
You’ve got this in your config:
But you’re seeing this in your errors:
This tells us that your hosting provider is redirecting SMTP traffic to their own mail server. Because this redirection is invisible to you, it’s left up to TLS to spot that the expected name does not match the presented certificate, and abort the connection, because this is in effect a man-in-the-middle attack.
You need to ask your provider to stop redirecting your SMTP traffic, or find a new hosting service.