Reputation: 1091
i am using phpmailer and i am getting following error:
Message was not sent Mailer Error: SMTP Error: Could not connect to SMTP host.
<?php
require("class.phpmailer.php");
$mailer = new PHPMailer();
$mailer->IsSMTP();
$mailer->Host = 'ssl://smtp.myhost.com:465';
$mailer->SMTPAuth = TRUE;
$mailer->Username = '[email protected]';
$mailer->Password = 'mypass';
$mailer->From = '[email protected]';
$mailer->FromName = 'myname';
$email1 = $_GET['email'];
$verification = rand();
$mailer->Body = 'Welcome to our site';
$mailer->Subject = 'verification';
$mailer->AddAddress($email1);
if(!$mailer->Send())
{
echo "Message was not sent<br/ >";
echo "Mailer Error: " . $mailer->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
note: i use "myhost.com" but it's not my real domain
Upvotes: 3
Views: 1183
Reputation: 163538
I believe you are specifying your host incorrectly. Try this instead:
$mailer->Host="smtp.myhost.com";
$mailer->Port=465;
$mailer->SMTPSecure="ssl"; //If this doesn't work, try 'tls'
If it still doesn't work, consider setting:
$mailer->SMTPDebug=1;
Also, make sure PHP's OpenSSL extension is enabled.
Upvotes: 4