สำหรับใครที่ยังไม่รู้จัก phpBB custom page สามารถ ศึกษาได้ก่อนจาก บทความนี้
สำหรับใครที่พอเขียนเป็นอยู่แล้ว ไปกันต่อเลย
เริ่มจาก include ไฟล์ที่จำเป็นต้องใช้ แบบ custom page
โค้ด: เลือกทั้งหมด
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
require_once($phpbb_root_path . 'common.' . $phpEx);
require_once($phpbb_root_path . 'includes/startup.' . $phpEx);
require_once($phpbb_root_path . 'includes/functions.' . $phpEx);
require_once($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
require_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
// สร้าง object messenger กำหนด false เป็นค่าเริ่มต้นเพื่อไม่ต้องให้เก็บเมลไว้ใน ระบบ queue
$messenger = new messenger(false);
// set ชื่อ template ของเมลที่จะใช้ ซึ่งไฟล์นี้ จะเก็บไว้ที่ language/en/email/email_notify.txt โดยที่ email_notify คือชื่อ template ไฟล์ข้อความ
$messenger->template('email_notify');
// กำหนด รายละเอียดของเมล
$to = '[email protected]';
$subject = 'Test Email by mindphp';
$message = 'This is a email. From ThaiVI';
$headers = 'From: [email protected]';
$messenger->headers($headers);
$messenger->to($to);
$messenger->from('[email protected]', 'mindphp');
$messenger->subject(html_entity_decode($subject));
$messenger->message = $message;
$messenger->send($message);
try {
$messenger->send();
echo 'Email sent successfully.';
} catch (\Exception $e) {
echo 'Failed to send email: ' . $e->getMessage();
}