หน้าเว็บ

วันอาทิตย์ที่ 10 สิงหาคม พ.ศ. 2551

แก้ปัญหา พิมพ์ subject ภาษาไทยไม่ได้ใน PHPList

อาการคือ เวลาส่งเมล์ แล้วถ้าพิมพ์หัวข้อ subject พอกด save จะไม่สามารถแสดงภาษาไทยได้ถูกต้อง

สำหรับคนที่ใช้ PHPList โดยไม่ได้เปลี่ยนภาษา (หรือเป็นภาษาอังกฤษ) สามารถไปแก้ที่ไฟล์ /lists/texts/englins.inc

โดยให้แก้จาก
$strCharSet = 'ISO-8859-1';
ให้เป็น
$strCharSet = 'UTF-8';
ก็จะสามารถใช้งานได้

ส่วนในตัว body นั้นก็ให้ไปตั้งค่า html charset และ text charset ใน configure ให้เป็น UTF-8 ทั้งคู่

**เพิ่มเติม
ตอนแรกใช้งานได้ แต่กลับมีปัญหาที่ตัว ภ. (ภ สำเภา) ไม่สามารถแสดงได้ถูก
วิธีแก้เพิ่มคือ ไปที่ไฟล์ admin/mysql.inc
ตรงฟังก์ชัน function Sql_Query($query,$ignore = 0) {
ให้เติม mysql_query("SET NAMES 'utf8'"); เข้าไป
function Sql_Query($query,$ignore = 0) {
mysql_query("SET NAMES 'utf8'");
if (isset($GLOBALS['lastquery'])) {
unset($GLOBALS['lastquery']);
}

แต่ว่าวิธีนี้คือตัวฐานข้อมูลก็ต้องตั้ง ให้เป็น utf-8 ด้วย

ระบบที่ทดสอบ
PHPList: 2.10.5

วันศุกร์ที่ 8 สิงหาคม พ.ศ. 2551

แก้ไขปัญหา Database error 1071 while doing query Specified key was too long; max key length is 1000 bytes ของ PHPList

เนื่องจากถ้าใช้ db เป็น MyISAM จะรองรับ index key ขนาดไม่เกิน 1000 bytes
แต่ว่า user_blacklist_data ใช้ email และ name เป็น index key ซึ่งมีขนาดรวมกันคือ 255+100 = 355 bytes
และถ้าใช้เป็น UTF แต่ละ character จะใช้ 3 bytes รวมเป็น 3*355 = 1065 bytes ซึ่งเกินที่กำหนด

วิธีแก้วิธีแรก สร้างตาราง user_blacklist_data ขึ้นมาเอง โดยลดขนาด email ลงเหลือ 233 bytes แทน ซึ่งปกติก็ไม่ค่อยมีใครใช้ถึงอยู่แล้ว
CREATE TABLE phplist_user_blacklist_data (email varchar(233)
not null unique,name varchar(100) not null,data text,index
emailidx (email),index emailnameidx (email,name))


หรือวิธีที่สอง ให้ใช้ InnoDB แทน MyISAM จะไม่เกิดปัญหานี้

ระบบที่ทดสอบ
PHPList: 2.10.5

ข้อมูลจาก
http://forums.phplist.com/viewtopic.php?t=8150
http://mantis.phplist.com/bug_view_advanced_page.php?bug_id=8583

วันพฤหัสบดีที่ 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