'How to use PHPMailer library on Hostgator
I am using PHPMailer class to send emails from my contact form to my gmail account on localhost and it works fine. But when I upload it on Hostgator servers, I get errors when trying to send email. Do I use IP Address or Hostname and which port should I use? Please Assist?
PHPMailer class
require ("PHPMailer/PHPMailerAutoload.php"); //including phpmailer class
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->SMTPDebug = 2;
$mail->Host = "108.167.172.144 "; //Server IP Address
$mail->SMTPSecure = "tls"; // Connect using a TLS connection
$mail->Port = 587; //Gmail SMTP port
$mail->SMTPAuth = true; // turn on SMTP authorization
$mail->Username = "*********@gmail.com"; // SMTP username
$mail->Password = "********"; // SMTP password
$mail->From = "$em"; //email of sender
$mail->FromName = "$nm"; //name of the sender
$mail->AddAddress("********@gmail.com", "Patwan"); //email address of recepient and name
$mail->AddReplyTo($em, $nm); //Address to which recepient will reply
$mail->WordWrap = 100; // set word wrap to 100 characters
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "Contact Form"; //subject of email
$mail->Body = "Name: " . $nm .
"<br>Phone: " . $phone .
"<br>Email: " . $em .
"<br>Subject: " . $value .
"<br>Message: " . $msg ;
Errors
250-smtp.gmail.com at your service, [108.167.189.105] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8
2017-02-16 07:38:56 CLIENT -> SERVER: STARTTLS
2017-02-16 07:38:56 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2017-02-16 07:38:56 CLIENT -> SERVER: EHLO www.pwebk.com
2017-02-16 07:38:56 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [108.167.189.105] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8
2017-02-16 07:38:56 CLIENT -> SERVER: AUTH LOGIN
2017-02-16 07:38:56 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2017-02-16 07:38:56 CLIENT -> SERVER: bW5kdW5ndTkxQGdtYWlsLmNvbQ==
2017-02-16 07:38:56 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2017-02-16 07:38:56 CLIENT -> SERVER: bWFydGlubm4=
2017-02-16 07:38:57 SERVER -> CLIENT: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 c192sm2741709oih.39 - gsmtp
2017-02-16 07:38:57 SMTP ERROR: Password command failed: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 c192sm2741709oih.39 - gsmtp
2017-02-16 07:38:57 SMTP Error: Could not authenticate.
2017-02-16 07:38:57 CLIENT -> SERVER: QUIT
2017-02-16 07:38:57 SERVER -> CLIENT: 221 2.0.0 closing connection c192sm2741709oih.39 - gsmtp
2017-02-16 07:38:57 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Form could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Solution 1:[1]
Host is 'mail.domainname.com'. Port is 465. Username is one of the email accounts you created on hostgator. Password is the email account's password. SMTPsecure is 'ssl'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Andy Prempeh |
