• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.5 Failed to send emails, tried everything - PHP Version 7.0.21

#1
Email to someone@gmail.com failed: stream_socket_enable_crypto(): Peer certificate CN=`server.notevenmyhost.net' did not match expected CN=`smtp.mailgun.com' - library/Zend/Mail/Protocol/Smtp.php:206

A little background:

So I recently moved to a new server, a VPS with cPanel. Shared with someone turns out of was working fine for few days but not out of nowhere I got this issue. I contacted the mailgun's team and they suggested me to upgrade my certificate. I got a Comodo SSL signed by cPanel itself and I'm getting an A grade on SSL test.

then Mailgun guys asked me to get server.notevenmyhost.net's certificate checked as it showed an F grade and SSL test says invalid. So I asked the other guy and he got it fixed too. Now his SSL tests also show the A Grade.

I thought maybe it has something to do with mailgun so I moved to sparkpost to test if the mails will be delivered or not, that didn't happen either i got the same error again.

Also importan to note is that I use server.notevenmyhost.net:2083 to login to my cPanel. I can use my own domain too but I use his'

after following this guide, I got another error which said

Email to someone@gmail.com failed: stream_context_set_option() expects exactly 4 parameters, 5 given - library/Zend/Mail/Protocol/Smtp.php:206

my server's logs have reached 9 pages of errors filled with this issue and my members are on a verge of crying.

I hope I can get some help here soon.
Thank you
 

Brogan

XenForo moderator
Staff member
#2
What are your SMTP settings?

What have you entered for the host name - localhost or the server address?
You should be using the latter.
 
#3
hey @Brogan Thanks for coming for help

My current smtp setting looks like this

16a362b61517.png

About the hostname. I have been trying to find a way to edit it but wasn't able to find anything inside admin panel.
then I looked for php settings, at admin.php?tools/phpinfo and it looks like I am using localhost for smtp.

16b363b31717.png

I'm not sure how should I edit it
 
#4
Update: I'm trying to add

SMTP = smtp.mailgun.org
smtp_port = 587

in my php.ini file

the port number seems to be updated but not the SMTP server

173371b95117.png
 

Mike

XenForo developer
Staff member
#5
If you're entering smtp.mailgun.com and you're getting an error with a different host name, it would appear that there's some sort of man-in-the-middle or proxying happening on your outgoing connectins. That may not be what you want. If you do want that, then this is a certificate that you need to make PHP trust (which would likely require a custom certificate list build). This is something you'd run into with any outgoing SSL connections, so it's unfortunately not related to XF.

stream_context_set_option() expects exactly 4 parameters, 5 given - library/Zend/Mail/Protocol/Smtp.php:206
While I would not recommend this, that line in question is wrong. It should be something like:
Code:
stream_context_set_option($this->_socket, 'ssl', 'verify_peer', false);
stream_context_set_option($this->_socket, 'ssl', 'verify_peer_name', false);
 
#6
Thank you @Mike. I think I will use that quick fix until I further investigate. I had to disable 2FA so members can login which was a big security risk for most members. Now I just added those two lines and it's working just fine until I check deeper.
For some reason, even my provider is clueless on what's happening.