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 = "from@email.com"; $mail->FromName = "you name"; $mail->Subject = "some subject"; $mail->MsgHTML("the message"); //$mail->AddReplyTo("reply@email.com","reply name");//they answer here, optional $mail->AddAddress("address@to.com","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!";
Related posts:
