1

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.

JonW
  • 145
  • 1
  • 1
  • 8
  • try replacing $mail->isSMTP(); to $mail->isSMTP(true); – Nitish Kumar Diwakar Feb 13 '18 at 08:17
  • Possible duplicate of [PHPMailer GoDaddy Server SMTP Connection Refused](https://stackoverflow.com/questions/21841834/phpmailer-godaddy-server-smtp-connection-refused) – Miggy Feb 13 '18 at 08:18
  • $mail->isSMTP(true) didn't work, I checked out that post, PHPmailer GoDaddy Server... It seems to be for emails that are hosted on Godaddy, I am using Gmail. I did try matching some of their settings but still no go – JonW Feb 13 '18 at 08:27
  • Are your settings in PHP.INI correct? – Mawg says reinstate Monica Feb 13 '18 at 08:39
  • the only thing in PHP.ini that I added (could not find the file in Goddady, from what I read you have to create your own. I created one in the root directory) allow_url_fopen=On – JonW Feb 13 '18 at 08:45
  • Your code is running on GoDaddy, trying to connect to gmail over SMTP, but GoDaddy doesn't allow that, exactly as the troubleshooting guide says. You must send via the GoDaddy mail servers, or via an HTTP mail API. @nitish, don't just make up random suggestions - passing true to `isSMTP` makes no difference. – Synchro Feb 13 '18 at 08:59

1 Answers1

0

So I contacted Godaddy, and they supplied me with a test script that ran PHPMailer on my shared server. The script ran fine and that just confused me more.

After a bit of more searching, I found that Godaddy was blocking SMTP, I confirmed this from one of the options in the script. I changed my code from SMTP to PHP mail() and it worked.

 $mail->isSendmail();

insted of $mail->isSMTP();

Now it takes longer than SMTP to send the email but it's not too long and it works, which right now is all that matters.

I put the file they gave me online (30-day temp) if anyone could use it. https://ufile.io/2kqkm

 That file has an option to send via SMTP or mail(). When I ran it through 
 SMTP on my Godaddy site I received an error, part of which stated: 
 We do not authorize the use of this system to transport unsolicited, 
 220 and/or bulk e-mail.

Thank you all for your help!!

JonW
  • 145
  • 1
  • 1
  • 8