mercredi 22 juin 2016

PearMailer, PHP7, and OpenSSL unable to connect to gmail with unknown error

I'm building a website, and part of it needs to send emails (one for account password reset links, the other for general user-admin contact). I've been using PearMailer to send emails through a GMail account, and that's worked fine...until now. For some reason, it's stopped sending emails, and it's giving me this very unhelpful error:

 [message] => Failed to connect to ssl://smtp.gmail.com:465 [SMTP: Failed to connect socket: fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Unknown error) (code: -1, response: )

openSSL is enabled, and all the credentials I'm using are correct (I can manually sign in to that GMail account using them).

This is the code I'm using, where $config holds the account credentials, and the $_POST data is from the Contact Us form (ignore the lack of sanitization on it while I'm developing):

    require_once "Mail.php";
        $params=array(
            "host"=>"ssl://smtp.gmail.com",
            "port"=>465,
            "auth"=>true,
            "username"=>$config["mailFrom"],
            "password"=>$config["mailPass"]
        );
        $headers=array(
            "To"=>$config["mailFrom"],
            "From"=>$_POST['user']." <".$_POST["reply-to"].">",
            "Content-type"=>"text/html",
            "Subject"=>$_POST['subject']
        );
        $mail=Mail::factory("smtp", $params);
        $sent=$mail->send($config["mailFrom"], $headers, htmlentities($_POST['body']));

It should be sending my GMail account an email from itself, but instead, it's giving me the error I mentioned above. After changing the to and from addresses, no matter what, it still gives me that error. Which is especially strange, since almost identical code is what I've been using to send password reset links, and that was working fine until just now; of course, it too is now failing to connect.

I can't find anything saying Google has changed its settings, and I absolutely haven't gone over the 2,000 messages per day limit that smtp.gmail.com is supposed to allow, so what's going on here?

Aucun commentaire:

Enregistrer un commentaire