1

I would appreciate i anyone can help me here. I am almost done with pset7 but I am stuck on the extra feature. I chose to send a mail to the user in order to reset the password, but can't make the server send it. I opened a new gmail account for this purpose.

The error I get from $mail->ErrorInfo is the following:

$mail->ErrorInfo is Mailer Error: SMTP Error: Could not connect to SMTP host.

And with $mail->SMTPDebug = 2, I get this message:

SMTP -> ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Name or service not known (0) SMTP Error: Could not connect to SMTP host.

I wrote a function _mail in functions.php that uses PHPMailer:

function _mail($to, $subject, $body)
{
    $mail = new PHPMailer();

    $mail->SMTPDebug = 2;                        // Enable verbose debug output

    $mail->isSMTP();                             // use SMPT   
    $mail->STMPAuth = true;                          
    $mail->Host = "smpt.gmail.com";
    $mail->SetFrom("*****@gmail.com");
    $mail->Username = "*****@gmail.com";         // SMTP username
    $mail->Password = "******";                  // SMTP password
    $mail->SMTPSecure = "tls";                   // Enable TLS, if SSL then port 465 
    $mail->Port = 587;

    $mail->IsHTML(true);
    $mail->addAddress($to);
    $mail->Subject = $subject;
    $mail->Body = $body;

    return $mail;
} 

and here the relevant snippet from the controller:

    else
    {   
        // recipient
        $to = $_POST["email"];

        // subject
        $subject = 'Reset CS50 Finance password';

        // message
        $body = '
        <html>
        <body>
            <p><a href="http://pset7/reset.php">Please click this link to reset the password</a></p>
        </body>
        </html>
        ';

        $mail = _mail($to, $subject, $body);

        if($mail->send() === false)
        {
            apologize ('Message could not be sent. Mailer Error: ' . $mail->ErrorInfo);
        }

        else 
        {
            echo 'The message has been sent';
        }
    }

Then the whole error message displays:

Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP host.

Does anyone have an idea of what is going on? Help is much appreciated.

0

you've got a typo in this line: $mail->Host = "smpt.gmail.com";

2
  • Thanks! Fixing this typo and another one in SMTPAuth made me see that the time of typos is not over for me yet ;) – masadeus Jun 2 '15 at 12:22
  • Anyways, other problems triggered that may have been solved by creating an "application specific password" in gmail. I rather chose instead to use another email account, not gmail. It made the trick! – masadeus Jun 2 '15 at 12:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .