Using PHPMailer on Hostgator (timeout when try to login into SMTP server)
Solved: The problem was that to use the service through hostgator, for some reason the user must log in using main dsn name and not the SMTP domain name.
I was using the simple PHP mail()
function to send emails and it was working fine but it didn't require to login into SMPT server. When I moved to PHPMailer
library I wrote this code to send email but I'm having timeout when when trying to do this login. According to info from hostgator, the SMTP server (with SSL/TSL) is at port 465
. So I wrote:
$mail = new PHPMailer;
$mail->SMTPDebug = 3;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'mail.mydomain.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'pass'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
$mail->setFrom('[email protected]', 'my name');
$mail->addAddress('[email protected]', 'someone'); // Add a recipient
$mail->addReplyTo('[email protected]', 'my name');
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'subject';
$mail->Body = 'msg body <b>bold!</b>';
$mail->AltBody = 'Corpo alternativo caso o primeiro não seja exibido';
if(!$mail->send())
{
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
else
{
echo 'Message has been sent';
}
But when this php file is called, besides not showing the echo
I placed before the code, it also waited the 300 seconds to open a modal warning me of the timeout error. Thanks in advance.
Solution 1:
I think the answer is in your code. You have lines like $mail->Host = 'mail.mydomain.com';
Be sure to switch all these out with actual domains. You have to use your www.com
website domain.
The following is wrong.
$mail->Host = 'mail.mydomain.com'; // Specify main and backup SMTP servers
I'm not surprised it won't send. Swap all the values out with real strings that matter to your site.