Using PHPMailer on Hostgator (timeout when try to login into SMTP server)
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.
Related videos on Youtube
fabionr
Updated on September 18, 2022Comments
-
fabionr almost 2 years
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 toPHPMailer
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 port465
. 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.-
Michael Hampton over 8 yearsCheck that you are trying to connect to the right host.
-
fabionr over 8 yearsWell, I went to this email's account page and searched for it's configs. There it said
Outgoing Server: mail.mydomain.com SMTP Port: 465
I just changed to "my domain" here but it is the same string. I'm using port 465 because it's through there to send using SSL/TLS -
Michael Hampton over 8 yearsI think you should have a chat with the service provider, then. The timeout in this circumstance is generally an indication that the connection has been firewalled.
-