I am trying to use PHPMailer with my contact forms on my site. I got it working when I was local with Mailtrap. I moved my site online with Godaddy and now it doesn't work. I can't even send the contact forms to the demo Mailtrap site let alone my Gmail (where I want to go). Any suggestions would help a lot.
I run the following code as a PHP function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
function send_email($email, $subject, $message, $alt_message, $headers){
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = Email::SMTP_HOST;
$mail->Username = Email::SMTP_USER;
$mail->Password = Email::SMTP_PASSWORD;
$mail->Port = Email::SMTP_PORT;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->setFrom('no-reply@email.ca', 'Admin');
$mail->addAddress($email);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AltBody = $alt_message;
if(!$mail->send()){
return false;
}else{
return true;
}
}
that code then links to my classes that has my email templates and all the variable inputs
class Email{
const SMTP_HOST = 'smtp.mailtrap.io';
const SMTP_PORT = 2525;
const SMTP_USER = '******';
const SMTP_PASSWORD = '*******';
function validate_email_temp($email, $message, $first_name,
$last_name){
return "long html email markup"
This worked great for Mailtrap when it was local, now that I moved it live I cannot get it to work with Mailtrap or Gmail.
Locally when I try to run it with Gmail I get:
Fatal error: Uncaught PHPMailer\PHPMailer\Exception: SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting in
C:\xampp\htdocs\lib\vendor\phpmailer\phpmailer\src\PHPMailer.php:1726 Stack
trace: #0
C:\xampp\htdocs\lib\vendor\phpmailer\phpmailer\src\PHPMailer.php(1481):
PHPMailer\PHPMailer\PHPMailer->smtpSend('Date: Mon, 12 F...', 'This is a
multi...') #1
C:\xampp\htdocs\lib\vendor\phpmailer\phpmailer\src\PHPMailer.php(1320):
PHPMailer\PHPMailer\PHPMailer->postSend() #2
C:\xampp\htdocs\lib\functions.php(68): PHPMailer\PHPMailer\PHPMailer-
>send() #3 C:\xampp\htdocs\lib\Contact.php(68):
send_email('email@gma...', 'test', '<html>\r\n<head><...', 'This is a
messa...', '') #4
C:\xampp\htdocs\public\inc\templates\contact_forms.php(4): Contact-
>contacts('gen', 'asdf@asdf', 'test', 'test', 'test', 'test') #5 {main}
thrown in C:\xampp\htdocs\lib\vendor\phpmailer\phpmailer\src\PHPMailer.php
on line 1726
When I try to run either Gmail or Mailtrap from Godaddy, nothing happens it just sits there trying to run. No error or anything.
Any help would be appreciated. Thank you!!
This post seems similar to post "PHPMailer GoDaddy Server SMTP Connection Refused", it isn't from what I can tell as that one is dealing with Godaddy hosted email and I am using Gmail. I did try to match some of their code but it doesnt work with Gmail.