Rafael Ruiz Muñoz
Rafael Ruiz Muñoz

Reputation: 5472

PHPMailer not working in my server

I built a droplet with Ubuntu with DigitalOcean and I'm trying to configure it to send emails with SMTP.

I know DigitalOcean blocks SMTP over IPv6 but not over IPv4 so I disabled IPv6 as this post says.

My script still doesn't work. I've tried with ports 25, 465 and 587. TLS and SSL.

I've installed sendmail for Ubuntu 14.04 but not working.

This is my script:

<?php
    require 'mail/PHPMailerAutoload.php';
    
    $mail = new PHPMailer;
    
    $to = $_GET['email'];
    
    $mail->isSMTP();
    $mail->Host = 'smtp.gmail.com';
    $mail->SMTPAuth = true;
    $mail->Username = '[email protected]';
    $mail->Password = '***';
    $mail->SMTPSecure = 'tls';
    $mail->Port = 587;
    
    $mail->setFrom('[email protected]', 'Rafael');
    
    $mail->addAddress($to);
    
    $mail->isHTML(true);
    
    $mail->Subject = 'Subject';
    $contents = ob_get_contents();
    $mail->Body    = "ao!";
    
    if(!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message has been sent';
    }
    print_r(error_get_last());
    

?>

The error presented is:

SMTP connect() failed.

I'm interested in sending email using SMTP so ->isSMTP() is required!

Where am I wrong?

Thank you very much.


EDIT:

doing: telnet smtp.gmail.com 587 I get:

Trying 74.125.133.108...

Connected to gmail-smtp-msa.l.google.com.

Escape character is '^]'.

220 smtp.gmail.com ESMTP w6sm13897014wjy.31 - gsmtp

and doing: openssl s_client -connect smtp.gmail.com:465 I get an answer as well...

What's wrong?

Upvotes: 0

Views: 8037

Answers (3)

AlboEinsOhms
AlboEinsOhms

Reputation: 1

Try commenting out line 8.

// $mail->isSMTP();

Upvotes: -1

Harry baldaniya
Harry baldaniya

Reputation: 167

On live server for send Mail using SMTP, Do it.

$mail->Host = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;

and Comment $mail->IsSMTP();

It's Working For Me....

Upvotes: 1

Jamil Farooq
Jamil Farooq

Reputation: 141

Beware of using Gmail from different devices. google doesn't allow and block immediately a location from where an account is used where it isn't supposed to use (in the eyes of google ofcourse).

Upvotes: 2

Related Questions