[PhpMailer] - ส่งอีเมล์บน Localhost ด้วย PHPMailer

[PhpMailer] - ส่งอีเมล์บน Localhost ด้วย PHPMailer

PHPMailer เป็น php class สำหรับใช้ส่งอีเมล์ สามารถส่งอีเมล์ผ่าน SMTP server ได้ ส่งได้ทั้งแบบ html และ text รวมไปถึงสามารถแนบไฟล์ในอีเมล์ที่ต้องการส่งได้ด้วย Feature ของ PHPMailer มีดังนี้ 
  • Probably the world's most popular code for sending email from PHP!
  • Used by many open-source projects: WordPress, Drupal, 1CRM, SugarCRM, Yii, Joomla! and many more
  • Integrated SMTP support - send without a local mail server
  • Send emails with multiple To, CC, BCC and Reply-to addresses
  • Multipart/alternative emails for mail clients that do not read HTML email
  • Add attachments, including inline
  • Support for UTF-8 content and 8bit, base64, binary, and quoted-printable encodings
  • SMTP authentication with LOGIN, PLAIN, CRAM-MD5 and XOAUTH2 mechanisms over SSL and SMTP+STARTTLS transports
  • Validates email addresses automatically
  • Protect against header injection attacks
  • Error messages in 47 languages!
  • DKIM and S/MIME signing support
  • Compatible with PHP 5.5 and later
  • Namespaced to prevent name clashes
  • Much more!
สามารถดาวน์โหลดได้ที่  คลิก
$mailto = "yourmail@[email protected]";
$mailSub = "Lorem Ipsum คือ เนื้อหาจำลองแบบเรียบๆ";
$mailMsg = "
  Lorem Ipsum คือ เนื้อหาจำลองแบบเรียบๆ ที่ใช้กันในธุรกิจงานพิมพ์หรืองานเรียงพิมพ์ 
  มันได้กลายมาเป็นเนื้อหาจำลองมาตรฐานของธุรกิจดังกล่าวมาตั้งแต่ศตวรรษที่
";

require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->IsSmtp();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587; // or 587
$mail->IsHTML(true);
$mail->CharSet="utf-8";
$mail->ContentType="text/html";
$mail->Username = "[email protected]"; //username gmail accound
$mail->Password = "email acount Password"; //password gmail accound
$mail->SetFrom("[email protected]", "Company name");
// $mail->AddReplyTo("[email protected]", "Company name");
$mail->Subject = $mailSub;
$mail ->Body = $mailMsg;
$mail ->AddAddress($mailto);

if(!$mail->Send()){
  echo "Mail Not Sent";
}
else{
  echo "Mail Sent";
}

หมายเหตุ ต้องตั้งค่าใน Gmail โดยเปิดแอปที่มีความปลอดภัยน้อยโดยพิมพ์คำว่า less secure apps ใน Google Search

จัดทำโปรแกรมคอมพิวเตอร์พัฒนาระบบงานธุรกิจส่วนตัวและหน่วยงาน

086-2887-987 (ท็อป)

Nakomah Studio   [email protected]

TOP