2

I have read every example out in the web and I still cant seem to connect to the GMAIL SMTP. Here is the code that I am running:

include("phpMailer/class.phpmailer.php"); // path to the PHPMailer class
$mail = new PHPMailer(); 
$mail->IsSMTP(); // send via SMTP

$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "myUsername"; // SMTP username
$mail->Password = "myPassword"; // SMTP password
$mail->SMTPDebug = 1;
$webmaster_email = "webMasterEmail@gmail.com"; //Reply to this email ID
$email="someone@gmail.com"; // Recipients email ID
$name="SomeonesName"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Me";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi,
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 tried setting the port in here and I also have the current set up with the following in the class.smtp.php file:

$host = "ssl://smtp.gmail.com";
$port = 465;

I keep getting the same error and I have made sure that ssl is enabled. The error I get is:

SMTP -> ERROR: Failed to connect to server: No connection could be made because the target machine actively refused it.(10061)
Nikola K.
  • 7,093
  • 13
  • 31
  • 39
hera87
  • 173
  • 1
  • 2
  • 11
  • I followed the example in http://deepakssn.blogspot.com/2006/06/gmail-php-send-email-using-php-with.html – hera87 Jul 03 '12 at 20:21
  • Possible duplicate [Send email using GMail SMTP server from PHP page](http://stackoverflow.com/questions/712392/send-email-using-gmail-smtp-server-from-php-page) – Adi Jul 03 '12 at 20:24
  • Im using PHPMailer and not the default Mail.php with php.ini config – hera87 Jul 03 '12 at 20:30
  • Maybe your hosting's firewall is blocking the conection with the SMTP, contact them to check this possibility. – Marcio Mazzucato Jul 03 '12 at 20:39
  • @MarcioSimao Im working off my localhost so there shouldnt be any problems with firewall rules – hera87 Jul 03 '12 at 20:56
  • Gmail SMTP requires SSL, check your `php.ini` and un-comment `php_openssl` then restart your webserver – Adi Jul 03 '12 at 22:14
  • @Adnan I already had that setting enabled and its still not making a difference – hera87 Jul 04 '12 at 03:10
  • $host = "tls://smtp.gmail.com"; $port = 587; – Synchro Mar 22 '13 at 13:26

1 Answers1

1

As I mentioned above I had already enabled ssl by getting rid of the ; on the line with php_openssl.dll and restarting Apache. I did some more reading and I found out that some people also had "[PHP_OPENSSL]" before the enabling command. I added it and restarted Apache and everything is working! Thanks for all the comments

In php.ini:

[PHP_OPENSSL]
extension=php_openssl.dll
Randell
  • 6,112
  • 6
  • 45
  • 70
hera87
  • 173
  • 1
  • 2
  • 11