Reputation: 31
I've been having this problem for a while now. I am intermittently getting an error when using PHPMailer to send mail from my OVH hosted email address using SMTP.
I have now setup a test file with hard-coded recipient, message, login details etc. The code is the same every time yet I have around a 75% success rate with the mail being sent on running the file. I have used this exact same function on a different host with zero issues.
This signals to me that the error is with OVH since my code is not changing yet is sometimes working and sometimes not, however, I have just contacted their support and they have found no technical issues with either my managed hosting or my email plan. I am also not being rate-limited (this error will occur within sending the first 2 or 3 emails). I tried setting up a different email address with them, same problem.
Here is the logs for when the error takes place:
2024-07-12 11:42:07 Connection: opening to ssl://ssl0.ovh.net:465, timeout=600, options=array()
2024-07-12 11:42:07 Connection failed. Error #2: stream_socket_client(): SSL: Success [/home/*/*/phpmailer/SMTP.php line 388]
2024-07-12 11:42:07 Connection failed. Error #2: stream_socket_client(): Failed to enable crypto [/home/*/*/phpmailer/SMTP.php line 388]
2024-07-12 11:42:07 Connection failed. Error #2: stream_socket_client(): Unable to connect to ssl://ssl0.ovh.net:465 (Unknown error) [/home/*/*/phpmailer/SMTP.php line 388]
2024-07-12 11:42:07 SMTP ERROR: Failed to connect to server: (0)
SMTP Error: Could not connect to SMTP host. Failed to connect to server
And here is the test file (censored parts but everything matches I've checked 1000x times):
ini_set ('display_errors', 1); ini_set ('display_startup_errors', 1); error_reporting (E_ALL);
require('phpmailer/PHPMailer.php');
require('phpmailer/SMTP.php');
require('phpmailer/Exception.php');
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$message = new PHPMailer(true);
$message->isSMTP();
$message->SMTPDebug = 4;
$message->Host = 'ssl0.ovh.net';
$message->SMTPAuth = true;
$message->SMTPAutoTLS = true; //I have tried false, no difference
$message->Username = 'confirmation@***.com';
$message->Password = '***';
$message->From = 'confirmation@***.com';
$message->SMTPSecure = 'ssl';
$message->Port = 465;
$message->isHTML(true);
$message->Timeout = 600;
$message->FromName = "Booking";
$message->addAddress("**My Personal Email**");
$message->Subject = "Subject";
$message->Body = "Test message body";
$message->send();
As I said, this works 75% of the time and it has never been used to send more than, say, 100 emails per day. I am stumped and would really appreciate any help since OVH are fairly convinced that the problem is not on their end.
Thanks in advance.
Upvotes: 0
Views: 148