Sample Code About Sending Emails Via Gmail

Programming, error messages and sample code > sample code

PHP
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<?php
include("class.phpmailer.php"); //you have to upload class files "class.phpmailer.php" and "class.smtp.php"
 
$mail = new PHPMailer();
 
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "demouser@gmail.com";
$mail->Password = "********";
 
$mail->From = "demouser@gmail.com";
$mail->FromName = "demouser";
 
$mail->AddAddress("test@test.com","test");
$mail->Subject = "This is the subject";
$mail->Body = "This is the body";
$mail->WordWrap = 50;
$mail->IsHTML(true);
 
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
?>
</body>
</html>