หน้าเว็บ

วันพฤหัสบดีที่ 7 สิงหาคม พ.ศ. 2551

แก้ PHPList ให้ทำงานกับ SMTP แบบ TLS

บังเอิญช่วงนี้ผมกำลัง implement ระบบ newsletter ให้กับองค์กรแห่งหนึ่งอยู่ ซึ่งผมก็เลือก PHPList มาใช้เพื่อการนี้

แต่คราวนี้มีปัญหาเกิดขึ้น เมื่อผมพยายามจะใช้ PHPList ส่งเมล์ โดยใช้ SMTP ขององค์กรแห่งนี้

ปัญหาคือว่า องค์กร นี้ใช้ SMTP Authentication, TLS, port 25

แต่ตัว PHPList เวอร์ชันล่าสุดที่ผมใช้นั้นคือ 2.10.5 นั้นไม่รองรับ TLS เพราะว่าลองไปดู module ในการส่งเมล์ของ PHPList จะเห็นว่ามันใช้ PHPMailer เวอร์ชัน1.73 (ดูจากไฟล์ Changelog อันบนสุด) แต่ว่าตัวที่จะรองรับต้องเป็น PHPMailer เวอร์ชัน 2 ขึ้นไป

ก็เลยลองไปโหลดเอา PHPMailer 2.2.1 มา แล้วทำกระบวนการตาม http://www.bookwish.org/phplist-and-gmail-smtp โดยทำการดัดแปลงเล็กน้อยจาก gmail ที่เป็น ssl ให้เป็น tls ดังนี้

สรุปคือ

1. extract PHPMailer 2.2.1 ออกมาจะได้โฟลเดอร์ชื่อ phpMailer_v2.2.1_ แล้วเอาไปไว้ที่ %YOURWWWROOT%/lists/admin โดย %YOURWWWROOT% เป็นที่อยู่ของ public_html หรือ htdocs หรือ wwwroot ของคุณ
2. แก้ไขไฟล์ %YOURWWWROOT%/lists/admin/class.phplistmailer.php
require_once dirname(__FILE__).'/accesscheck.php';

#require( dirname(__FILE__) . '/phpmailer/class.phpmailer.php');
require( dirname(__FILE__) . '/phpmailer_v2.2.1_/class.phpmailer.php');
require( dirname(__FILE__) . '/phpmailer_v2.2.1_/class.smtp.php');


3. ในไฟล์เดียวกัน แก้ฟังก์ชัน PHPlistMailer
...
if (isset($GLOBALS['phpmailer_smtpuser])...
$this->SMTPAuth=true;
$this->SMTPSecure="tls";
$this->Port=$GLOBALS['phpmailer_smtpport'];
$this->Username=$GLOBALS['phpmailer_smtpuser'];
$this->Password=$GLOBALS['phpmailer_smtppassword'];
...

4. ในไฟล์เดียวกัน ต่อจากเดิมลงมาหน่อย แก้
if (!$this->Host || $ip == $this->Host) {
$this->Mailer = "mail";
# logEvent('Sending via mail');
} else {
$this->Mailer = "smtp";
# logEvent('Sending via smtp');
}

ให้เป็น
if (!$this->Host) {
$this->Mailer = "mail";
# logEvent('Sending via mail');
} else {
$this->Mailer = "smtp";
$this->IsSMTP();
# logEvent('Sending via smtp');
}


5.แก้ไฟล์ %YOURWWWROOT%/ lists/config/config.php

...
define("PHPMAILERHOST",'mail.yoursmtpdomain.com');
...
$phpmailer_smtpuser='smtp username';
$phpmailer_smtppassword='smtp password';
$phpmailer_smtpport=25;
...

เป็นอันใช้ได้

ระบบที่ทดสอบ

PHPList: 2.10.5

Web Server: Apache2.2

Database: MySQL5

2 ความคิดเห็น:

ไม่ระบุชื่อ กล่าวว่า...

ขอคำแนะนำครับ
ผมใช้แล้วติดว่า คลิกไปไหนก็ขึ้น
HTTP Error 403 - Forbidden
ต้องแก้ไขไงครับ

KaizerWing กล่าวว่า...

อาการคือไม่สามารถ access ไฟล์ได้ครับ ลองตรวจสอบ .htaccess ในโฟลเดอร์หลักดูครับ ว่าเราให้สิทธิในการเข้าถึงไฟล์พวก index.php ได้รึเปล่า

หรือไม่อาจเกิดจาก apache ไม่ได้ตั้งค่า DirectoryIndex ให้มี index.html index.php ไว้ครับ

ลองอ่านเพิ่มเติมสาเหตุและวิธีแก้อื่นๆได้ที่
http://www.cyberciti.biz/faq/apache-403-forbidden-error-and-solution/