Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't connect to ssl://smtp.gmail.com:465 #455

Closed
ghost opened this issue Jul 12, 2015 · 13 comments
Closed

Can't connect to ssl://smtp.gmail.com:465 #455

ghost opened this issue Jul 12, 2015 · 13 comments

Comments

@ghost
Copy link

ghost commented Jul 12, 2015

Hi!

PHPMailer works on localhost but not on my webserver.

$mail = new PHPMailer;

$mail->SMTPDebug = 4;
$mail->Debugoutput = 'html';

$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = $admin['data_email'];
$mail->Password = '...';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;

$mail->From = $admin['data_email'];
$mail->FromName = $admin['data_name'];
$mail->addAddress($email, $name);
$mail->addReplyTo('no-reply@erik-edgren.nu', 'Automatiserad e-post');
# $mail->addCC('cc@example.com');
# $mail->addBCC('bcc@example.com');

# $mail->addAttachment('footer.php');
$mail->isHTML(true);

$mail->Subject = utf8_decode($subject);
$mail->Body = utf8_decode($content);
# $mail->AltBody = utf8_decode($content);

if(!$mail->send()) {
    echo 'email-error|'.$mail->ErrorInfo;
} else {
    echo 'email-sended';
}
Connection: opening to ssl://smtp.gmail.com:465, timeout=300, options=array ()
SMTP ERROR: Failed to connect to server: (0)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

What's wrong and how can I fix this issue?

@Synchro
Copy link
Member

Synchro commented Jul 12, 2015

Just a wild guess here, but you could go to https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting where it will tell you exactly what's wrong.

@Synchro Synchro closed this as completed Jul 12, 2015
@ghost
Copy link
Author

ghost commented Jul 12, 2015

I have already tried those settings. I have also tried to change the permissions of all the class files from 644 to 755. Didn't work. Tried 777 instead. Same result so I changed back to 644. I have double checked the connection setup and everything works just fine on localhost but not on my webserver.

@Synchro
Copy link
Member

Synchro commented Jul 12, 2015

This has nothing to do with permissions. Read the troubleshooting guide and it will tell you what you need to do with gmail - it may involve using the xoauth dev branch.

@ghost
Copy link
Author

ghost commented Jul 12, 2015

openssl is enabled on the webserver. I have read the troubleshooting a "million" times now. Nothing works! The webserver is on a web hotel but it has a lot of issues so I'm on my way to create my own webserver. It will be a huge relief!

@Synchro
Copy link
Member

Synchro commented Jul 12, 2015

If nothing is working, it just sounds like you have connectivity problems, which is what the DNS and telnet tests in the guide will tell you.

@boomsya
Copy link

boomsya commented Mar 28, 2016

the same problem after update php 5.4 to 7.0.4

2016-03-28 14:38:30 Invalid address: Ваш пенсійний консультант
2016-03-28 14:38:30 Connection: opening to ssl://mail.site.com:465, timeout=300, options=array (
)
2016-03-28 14:38:30 SMTP ERROR: Failed to connect to server: (0)
2016-03-28 14:38:30 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

@Synchro
Copy link
Member

Synchro commented Mar 28, 2016

Follow the guide. If you don't do what it says I can't help you.

@ivantcholakov
Copy link
Contributor

2016-03-28 14:38:30 Invalid address: Ваш пенсійний консультант

@Synchro
Copy link
Member

Synchro commented Mar 28, 2016

Please don't hijack unrelated threads or post random unrelated stuff. It's not helpful.

@boomsya
Copy link

boomsya commented Mar 28, 2016

i resolve this problem in file libraries/vendor/phpmailer/phpmailer/class.phpmailer.php
only add

    $options= array_merge( array('ssl' => array (
                    'verify_peer' => false,
                    'verify_peer_name' => false,
                    'allow_self_signed' => true)
                    ), 
                $options
                );

in function public function smtpConnect($options = array())

@Synchro
Copy link
Member

Synchro commented Mar 28, 2016

Don't do that. You're undermining the point of using a library and your code will break when it gets updated. Read the docs and it tells you how to do that without altering library code.

@boomsya
Copy link

boomsya commented Mar 29, 2016

thanks. i will try

@bitabs
Copy link

bitabs commented Apr 17, 2016

Guys, I have had the same problem and I fixed it by just simply doing the following:
$mail->Host = 'tls://smtp.gmail.com:587';

You guys should do the same

@PHPMailer PHPMailer locked and limited conversation to collaborators Apr 17, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants