Send Mail by GMail

1. โหลดไฟล์ php class ที่ชื่อว่า phpmailer ก่อน
2. เปิดใช้งาน openssl โดยการ เอาเครื่องหมาย ; หน้า extension=php_openssl.dll จาก php.ini ออก และ Save แล้ว restart Apache
3.ตัวอย่าง code

<?php

require(“class.phpmailer.php”);
require(“class.smtp.php”);

$mail=new PHPMailer();

$mail->IsSMTP();
$mail->IsHTML(true);

$mail->SMTPAuth = true;
$mail->SMTPSecure = “ssl”;
$mail->Host = “smtp.gmail.com”;
$mail->Port = 465;

$mail->Username = “username@gmail.com“;
$mail->Password = “password“;

$mail->From = “username@gmail.com“;
$mail->FromName = “Sender Name“;
$mail->Subject = “This is a testing subject from gmail“;
$mail->Body = “Hi,This is testing <b>HTML</b> message.”;

$mail->AddAddress(“your-friend@domain.com“,”your-friend@domain.com“);
if(!$mail->Send()) {
echo “Mailer Error: ” . $mail->ErrorInfo;
} else {
echo “Message has been sent”;
}
?>

Credit 1
Credit 2

Download PHPMailer


Comments

Popular posts from this blog

การตั้งเวลาระหว่าง Server และ Client

วิธีตั้งค่า NTP บน Primary Domain Controller

เทคนิค Ghost XP ข้าม Spec