I'm trying to use the PhpMailer on a managed server (I only have access via cPanel), and I'm getting this error:
SERVER -> CLIENT:
CLIENT -> SERVER: EHLO stefanomenci.com
SERVER -> CLIENT: HTTP/1.1 301 Moved
[...]
SMTP ERROR: EHLO command failed: HTTP/1.1 301 Moved
This is the script:
require ("/path/to/class.phpmailer.php");
$mail = new PHPMailer();
$mail->SMTPDebug = 2;
$mail->IsSMTP();
$mail->Host = "mydomain.com";
$mail->Port = 2096;
$mail->SMTPAuth = true;
$mail->Username = "name@mydomain.com";
$mail->Password = "****";
$mail->From = "name@mydomain.com";
$mail->FromName = "Name";
$mail->AddAddress("myaddress@gmail.com");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "Subject";
$mail->Body = "y<b>a</b>y";
$mail->AltBody = "yay";
$mail->Send();
If port is wrong it fails immediately with "failed to connect to the server".
If port is missing it says "Please turn on SMTP Authentication in your mail client, or login to the server before sending your message."
If port is correct it waits 10 seconds and shows the error shown above, regardless of the user name and password being correct or not.
Removing $mail->IsSMTP()
works, but often the emails go straight to the spam folder.
I found many posts about similar problem with PhpMailer, but they usually use Google instead of mydomain.com and they never have this error message.
Use either port 25 or 465 as mentioned above. On port 2096 is running a webserver as we can see in the connection ( SERVER -> CLIENT: HTTP/1.1 301 Moved ).