Rakesh
Rakesh

Reputation: 2790

PHP Mailer SMTP ERROR

Hi I am using phpMailer For sending email. Its working fine on server, but when i am trying to send mail from my local machine(localhost) it giving me error. I am using GMAIL smtp

<?
require("lib/class.phpmailer.php"); 
$mail = new PHPMailer();
$mail->IsSMTP(); 
$mail->SMTPAuth = true;
$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465; 
$mail->Username = "[email protected]";  // SMTP username
$mail->Password = "XXXXXXX"; // SMTP password
$mail->From = $email; 
$mail->AddAddress("[email protected]", "XX XX XX");
$mail->WordWrap = 50;
$mail->IsHTML(true); 
$mail->Subject = "You have received feedback from your website!";
$mail->Body    = $message;
$mail->AltBody = $message; 
if(!$mail->Send())
 {
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
    exit;
 }

 }
 ?>

and the error is

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

Mailer Error: SMTP Error: Could not connect to SMTP host.

It's working fine in my server.

Upvotes: 0

Views: 5392

Answers (1)

Aravind.HU
Aravind.HU

Reputation: 9472

Okay I got it in local here is the code that I used

<?php
    require("phpmailer/class.phpmailer.php");
    $mail = new PHPMailer();
    $mail->IsSMTP(); // send via SMTP
    IsSMTP(); // send via SMTP
    $mail->SMTPAuth = true; // turn on SMTP authentication
    $mail->Username = "[email protected]"; // SMTP username
    $mail->Password = "password"; // SMTP password
    $webmaster_email = "[email protected]"; //Reply to this email ID
    $email="[email protected]"; // Recipients email ID
    $name="name"; // Recipient's name
    $mail->From = $webmaster_email;
    $mail->FromName = "Webmaster";
    $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 = "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";
    }
    ?>

Upvotes: 1

Related Questions