Hello friends following script will work for sending mail with using of phpmalier class and gmail as smtp.This will be work for you if there is no mail support to your domain. it will be working in localhost also.
Download php mailer class from
PHP Code
After that at the php file write the below code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <?php require("includes/class.phpmailer.php"); $mailer = new PHPMailer(); $mailer->IsSMTP(); $mailer->Host = "smtp.gmail.com:587"; $mailer->SMTPAuth = TRUE; $mailer->Username = "{somename}@gmail.com"; // Change this to your gmail adress $mailer->Password = "{password}"; // Change this to your gmail password $mailer->From = "{someid}@gmail.com"; // This HAVE TO be your gmail adress $mailer->FromName = "Anil Labs"; // This is the from name in the email, you can put anything you like here $mailer->Body = "This is the main body from ANIL LABS"; $mailer->Subject = "This is mail from anil labs"; $mailer->AddAddress("{toaddress email id}"); // This is where you put the email adress of the person you want to mail if(!$mailer->Send()) { echo "Message was not sent<br/ >"; echo "Mailer Error: " . $mailer->ErrorInfo; } else { echo "Message has been sent"; } ?> |
Hope that it will be useful.









Hi,
I tried ur code it is giving me following error
Message was not sent
Mailer Error: Language string failed to load: connect_host
please advice
Hi Rahul,
Thank you for intimating me,
Just change the gmail smtp like:
$mailer->Host = ‘smtp.gmail.com:587′;
And at class.phpmailer.php file change the
public $SMTPAuth = true;
Then it will be work.
how to attach the doc file in this code?
hey its still not working.its not connecting to smtp
Hello, Anil
I am getting the error
SMTP Error: Could not authenticate. Message was not sent
Mailer Error: SMTP Error: Could not authenticate.