PHP SEND EMAIL WITH PHPMAILER USING GOOGLE APPS

PHP Result Center PHP Result Center เป็นหมวด ที่ไว้รวบรวม โปรแกรม Code php Javascript CSS CMS

Moderator: mindphp, ผู้ดูแลกระดาน

siamfocus
PHP Newbie
PHP Newbie
โพสต์: 6
ลงทะเบียนเมื่อ: 26/01/2012 10:19 am
ติดต่อ:

PHP SEND EMAIL WITH PHPMAILER USING GOOGLE APPS

โพสต์ที่ยังไม่ได้อ่าน โดย siamfocus »

วันนี้ได้มีโอกาสรื้อ ฟังก์ชั่น ส่ง Email เก่าๆ นะครับ เลยจำได้ว่าทำไว้นานแล้ว และก็น่าจะมีประโยชน์กับเพื่อน ๆ สามารถเอาไปใช้พัฒนาต่อได้ไม่น้อยเลยทีเดียว

โดย ฟังก์ชั่นนี้เป็น ฟังก์ชั่น ที่ใช้ในการส่ง Email จาก hosting ของเรานะครับ แต่ใช้ username กับ paasword ของ Google App ซึ้งปัจจุบัน หลายเว็บก็นิยมใช้ Google App กันหมดแล้ว

โดยตัวอย่างนี้ผม ทำการเขียนคำอธิบายไว้ สามารถนำไปประยุกต์ใช้ต่อกันได้เล้ยยย โดยทดสอบบน Hosting ของผมแล้ว ส่งออกจริง ไรจริง เอาไปใช้ได้เล้ยยยยยย

โค้ด: เลือกทั้งหมด

<?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   = "[email protected]";  // GMAIL username
  $mail->Password   = "MAIL_GOOGLE_APP_PASSWORD";            // GMAIL password
  $mail->AddReplyTo('[email protected]', 'REPLY_TO'); //ได้เมลล์แล้วตอบกลับถึงใคร
  $mail->AddAddress($to, ''); //ถึงใคร
  $mail->AddBcc('[email protected]', 'BCC'); //สำเนาลับถึงใคร
  $mail->SetFrom('[email protected]', 'SEND_FORM'); //ใครเป็นคนส่ง
//'  $mail->AddReplyTo('[email protected]', '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("[email protected]","ทดสอบการส่ง Email","<hr>ทดสอบ Body HTML <br><hr>");
?>
http://freecode.siamfocus.com/send_emai ... ogle_apps/
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 58