13

i am trying to use phpMailer to send confirmation messages to users via email. my code is this:

<?php
include("class.phpmailer.php");
include("class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "ssl://smtp.gmail.com"; // specify main and backup server
$mail->Port = 465; // set the port to use
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "sender@gmail.com"; // your SMTP username or your gmail username
$mail->Password = "mypasswrord"; // your SMTP password or your gmail password
$from = "webmaster@example.com"; // Reply to this email
$to="receiver@yahoo.com"; // Recipients email ID
$name="Jersey Name"; // Recipient's name
$mail->From = $from;
$mail->FromName = "Webmaster"; // Name to indicate where the email came from when the recepient received
$mail->AddAddress($to,$name);
$mail->AddReplyTo($from,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "Sending Email From Php Using Gmail";
$mail->Body = "This Email Send through phpmailer, This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>

i already enabled ssl in php.ini.

PS> sender@gmail.com is a mask email to protect the privacy. but i did put a true email address in that part

Synchro
  • 35,538
  • 15
  • 81
  • 104

4 Answers4

18

in you php.ini make sure you have uncommented the line with

extension=php_openssl.dll
DarthJDG
  • 16,511
  • 11
  • 49
  • 56
jerome
  • 196
  • 2
0

From here

2) Comment out the following lines of code in class.phpmailer.php

/*
if(strstr($hosts[$index], ":"))
list($host, $port) = explode(":",
$hosts[$index]); else 
*/

Try this if you haven't already.

Musa
  • 96,336
  • 17
  • 118
  • 137
Mridul Kashatria
  • 4,157
  • 2
  • 18
  • 15
0

This page has code the author claims "worked flawlessly".

The only real difference I see between his and yours is that his has:

$mail->Mailer = "smtp";

I guess I would start with his code exactly to see if it works, and then debug from there.

Nemo
  • 70,042
  • 10
  • 116
  • 153
  • So his code works for him but not for you? Then there is something different in the environment... Try `telnet smtp.gmail.com 465` to make sure it is not a firewall issue. Next most likely cause is a failure to validate the server's SSL cert. – Nemo May 29 '11 at 16:54
0

wrong:

$mail->Host = "ssl://smtp.gmail.com"; // specify main and backup server

good:

$mail->Host = "smtp.gmail.com"; // specify main and backup server
Code Lღver
  • 15,573
  • 16
  • 56
  • 75
macieq
  • 11