Can't send an email using a google apps account with PHPMailer

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2011-03-14T16:07:19Z Indexed on 2011/03/14 16:10 UTC
Read the original article Hit count: 290

Filed under:
|
|

I'm trying to simply send an email using my google apps account with php. I am able to send an email in a .net application using the port 587 host smtp.googlemail.com and SSL enabled. The username is my full email address.

require_once('PHPMailer_v5.1\class.phpmailer.php');

try {
    $mail  = new PHPMailer();
    $mail->Mailer   = 'smtp';
    $mail->SMTPSecure = 'tls';
    $mail->Host     = $host;
    $mail->Port     = 587;
    $mail->SMTPAuth = true;
    $mail->Username = $from;
    $mail->Password = $password;

    $mail->AddAddress($to, $to_name);   
    $mail->From       = $from;
    $mail->FromName   = $from_name;
    $mail->Subject    = $subject;
    $mail->MsgHTML($body);
    $mail->IsHTML(true);

    $mail->Send();
} catch (phpmailerException $e) {
    echo $e->errorMessage();
} catch (Exception $e) {
    echo $e->getMessage();
}

Haven't been able to get this to work, but I've tried several different variations of this.

$mail->SMTPSecure = 'ssl'; // Error: Could not connect to SMTP host.
$mail->SMTPSecure = 'tls'; // Takes forever, then I get "this stream does not support SSL/crypto PHPMailer_v5.1\class.smtp.php"

I don't care how, but I need to send an email using gmail here. It can be with this library or a different one.

© Stack Overflow or respective owner

Related posts about php

Related posts about email