0

I'm trying to get my mailing system running. It worked perfectly fine on my local machine but now on the server the mailing seems to fail.

I've managed to get one message from gmail. It said that they have blocked the Sign In, I've said, ok that's me and tried again but this time I didn't even get an error message anymore.

UPDATE: I've done some more research and found out, that SMTP connect() failed, here is the code

$mail = new PHPMailer();

$mail->isSMTP();                                            
$mail->Host       = 'smtp.gmail.com';
$mail->SMTPAuth   = true;
$mail->Username   = 'mywebsite.service@gmail.com';
$mail->Password   = 'mypassword';

// $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
// $mail->Port       = 465;

$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port       = 587;

$mail->setFrom('mywebsite.service@gmail.com', 'MyWebsite Team');
$mail->AddReplyTo( 'mywebsite.service@gmail.com', 'Contact MyWebsite Service' );
$mail->addAddress($email, $name);
$mail->isHTML(true);
$mail->Subject = "Membership, Please Verify Your Account";
$mail->Body = "Content";

if(!$mail->Send()) {
    echo "Error sending: " . $mail->ErrorInfo;
}

As you can see I've set the port to 456. And I've also turned on "access to less secure apps" in my account and used "DisplayUnlockCaptcha" as described here: gmail-keeps-blocking-phpmailer-sign-in

Despite all that it still doesn't work..

UPDATE: I've tried both port 456 and port 587 both just give me the SMTP connect() failed error..

There must be some way to find out why this did not work?

Miger
  • 1,175
  • 1
  • 12
  • 33

1 Answers1

0

This combination will not work because it's asking for explicit TLS on a port that usually expects implicit TLS:

$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port       = 465;

As the docs on this say, STARTTLS mode will not work on port 465. Either change to SMTPS mode, or change the port, that is, do either of these:

$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port       = 465;

or

$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port       = 587;
Synchro
  • 35,538
  • 15
  • 81
  • 104
  • It still doesn't work.. I get no mail, no warning, nothing.. How can I even go about tracking if the email was sent or not? – Miger Jan 29 '20 at 18:34
  • If you read the rest of the docs I pointed you at, you'd find a big list of things to look at, such as [how to enable debug output](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#enabling-debug-output). – Synchro Jan 29 '20 at 18:42
  • Well I know how to debug.. anyway I'm looking into it.. I've got a few ideas, thanks! – Miger Jan 29 '20 at 18:44
  • Note that if it works ok on your test machine but not on your server, it's most likely due to the thing that's different, i.e. your server and network rather than your script. Check whether your ISP blocks outbound SMTP - it's very common, and also covered in the guide. – Synchro Jan 29 '20 at 18:45
  • I've updated my question, I've found out that the mail doesn't send.. which is strange because I got a warning mail once before which blocked the sign in... well, I hope you are someone else can help me out some more, this should be working until tomorrow.. and I'm really out of ideas, the doc doesn't help much.. – Miger Jan 29 '20 at 19:24
  • So what happened when you tried the telnet and openssl tests? – Synchro Jan 30 '20 at 06:54
  • 1
    I've tested it out a few times now.. seems gmail is just being very complicated.. I keep doing the activate captcha thing, log in and out of my account whenever I update the file system of the server.. It sort of works now.. Not that I got a clear solution now, but your comments where helpful for debugging an seeing what's actually going on. Thanks! – Miger Jan 30 '20 at 14:46