// ++++++++++++++++++++++++++++++++++++++++++++++++++++
// + PROJECT NAME : PHP SEND EMAIL WITH PHPMAILER USING GOOGLE APPS
// + URL DESTINAMTION : http://freecode.siamfocus.com/send_email_with_phpmailer_using_google_apps/
// + CREATED BY : SiAMFOCUS.COM
// + CONTACT : ADMIN@SIAMFOCUS.COM
// + CREATED DATE : 27-12-2012
// + TECHNOLOGY : PHP,MYSQL,GOOGLE APPS
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
<?php
require_once('class.phpmailer.php');
function sendmail($to,$subject,$detail){
$mail = new PHPMailer(true); // ใช้ร่วมกับ PHPMailer
$mail->CharSet = "UTF-8";
$mail->IsSMTP(); // ใช้ SMTP ในการส่ง
try {
$mail->Host = "mail.YOURDOMAIN.com"; // SMTP server
$mail->SMTPDebug = 0; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "MAIL_GOOGLE_APP@YOURDOMAIN.com"; // GMAIL username
$mail->Password = "MAIL_GOOGLE_APP_PASSWORD"; // GMAIL password
$mail->AddReplyTo('REPLY@YOURDOMAIN.com', 'REPLY_TO'); //ได้เมลล์แล้วตอบกลับถึงใคร
$mail->AddAddress($to, ''); //ถึงใคร
$mail->AddBcc('BCC@YOURDOMAIN.com', 'BCC'); //สำเนาลับถึงใคร
$mail->SetFrom('MAIL_GOOGLE_APP@YOURDOMAIN.com', 'SEND_FORM'); //ใครเป็นคนส่ง
//' $mail->AddReplyTo('admin@siamfocus.com', 'D');
$mail->Subject = $subject;
$mail->MsgHTML($detail);
$mail->Send();
//echo "Message Sent OK\n";
} catch (phpmailerException $e) {
//echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
//echo $e->getMessage(); //Boring error messages from anything else!
}
}
sendmail("admin@siamfocus.com","ทดสอบการส่ง Email","
ทดสอบ Body HTML
");
?>