Web development, scripts, source code and IT stuff
Send email using Gmail and PHP
This is really useful if you don’t have an email server.
Using your Gmail account for sending emails is great ;)
Steps:
- Dowload the latest version of PHPmailer class
- Include it in your script
- Test with this code:
$mail = new PHPMailer(); $mail->IsSMTP(); //GMAIL config $mail->SMTPAuth = true; // enable SMTP authentication $mail->SMTPSecure = "ssl"; // sets the prefix to the server $mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server $mail->Port = 465; // set the SMTP port for the GMAIL server $mail->Username = "gmailusername"; // GMAIL username $mail->Password = "gmailpassword"; // GMAIL password //End Gmail $mail->From = "[email protected]"; $mail->FromName = "you name"; $mail->Subject = "some subject"; $mail->MsgHTML("the message"); //$mail->AddReplyTo("[email protected]","reply name");//they answer here, optional $mail->AddAddress("[email protected]","name to"); $mail->IsHTML(true); // send as HTML if(!$mail->Send()) {//to see if we return a message or a value bolean echo "Mailer Error: " . $mail->ErrorInfo; } else echo "Message sent!";
I used the code but i got the following error. what could be the probable reason. the internet connection is up and running while i am using this script..Please help..
Error:
SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.
Maybe a problem with you hosting, port closed or something like that
hello..
I would like to ask steps that i should follow to run send phpmailer code using gmail server.
:razz: :sad: :evil: :grin: :eek: :shock: :???:
thank you it works :)
Welcome!
Hi,
Please tell me how to send mail to gmail account without using SMTP.
Best Regards,
Kalpesh