Can't send an email using a google apps account with PHPMailer
- by Chris
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.