Set up Email cho Drupal
Xin Chào,
Mình mới install Drupal 6.1 trên Brinkster (www.Brinkster.com - Linux Hosting plan). Mọi thứ đều OK ngoại trừ hộ thống không send email.
Khi tạo một tài khoản, website trả thông báo:
Unable to send e-mail. Please contact the site admin, if the problem persists.
Đặc biệt là dòng thông báo tiếp theo lại báo send được:
Your password and further instructions have been sent to your e-mail address.
Note: user không hề nhận được bất cứ email nào từ website
Screenshot có thể xem tại đây: http://farm3.static.flickr.com/2204/2365988912_ea6dba0d1e_o.jpg
Mình thử tìm kiếm trên Drupal.org nhưng có vẻ vấn đề là do hosting provider (Brinkster) kô hổ trợ Drupal email component. Mình không biết chính xác nguyên nhân và làm sao để nó work đựoc. Có bà con nào giúp hay chỉ cách dùm được không? (xin lỗi là mình không rành PHP lắm :( )
Đây là thông tin của phpinfo() trên hosting của mình. (xin xem attached image)
Và đây là một số thông số mà mình nghĩ có liên quan:
sendmail_from no value no value
sendmail _path /usr/sbin/sendmail -t -i/usr/sbin/sendmail -t -i
serialize_precision 100100
short_open_tag OnOn
SMTP localhost localhost
smtp_port 2525

Có lẽ phải nhờ tech
Có lẽ phải nhờ tech bên đó hỗ trợ thôi. Nói họ gửi một thí dụ, rồi bắt chước đó mà hack hàm mail của Drupal.
Thế Hồng
Gửi Thế Hồng
Mình có tham khảo một example của Brinkster về send email bằng phpmailer và đã tạo được test page (php). Test page này send được email.
Tuy nhiên, khi dùng vào Drupal thì vẫn còn bị bug, không biết là đoạn code dưới đây sai chỗ nào:
Step 1: thêm dòng này vào cuối file setting.php
$conf["smtp_library"] = "includes/phpmailer.inc";
( Cái này để bảo Drupal xài smtp library thay vì dùng cách send default)
Step 2: add file phpmailer.inc này vào folder "includes"
<?php
include_once '/sites/includes/class.phpmailer.php'; // Noi de module phpmailer
function user_mail_wrapper($mail, $subject, $message, $header) {
$mailer = new PHPMailer(); // instantiate a new mailer
$mailer->IsSMTP(); // send via SMTP
$mailer->Host = "mail.brinkster.com"; // SMTP server
$mailer->SMTPAuth = true; // turn on SMTP authentication
$mailer->Username = 'noreply@domain.com'; // SMTP username
$mailer->Password = 'emailpassword'; // SMTP password
$mailer->AddAddress($mail); // can only send to one recipient
$mailer->From = 'noreply@domain.com'; // from address (default root@localhost)
$mailer->FromName = 'Admin'; // from name (default 'root user')
$mailer->Subject = $subject;
$mailer->AddCustomHeader( explode("\n", $header)); // add custom header info
// if body is not formatted properly change str_replace - see user.module user_mail() for details
$mailer->Body = str_replace("\n", "\r\n", $message); // Body of message
if(!$mailer->Send()){
watchdog('error', 'mail send error: ' . $mailer->ErrorInfo);
return false;
}
return true;
}
?>
Note: Mình test các thông số trên với một email test page (php), và nó gửi email được --> các thông số là chính xác.
Step 3: thử đăng ký một user mới, không còn thông báo lỗi "unable send email...", nhưng vấn đề là nó trả về blank page.
Đoạn code trên mình tham khảo một bài viết cho Drupal 4.x và 5.x . Không biết có gì thay đổi cách nhận value trả về khi send email trong drupal 6 không nhỉ?
Thân,
Thay thể
<?phpinclude_once '/sites/includes/class.phpmailer.php'; // Noi de module phpmailer
?>
thành
<?phpinclude_once base_path () . '/sites/includes/class.phpmailer.php'; // Noi de module phpmailer
?>
user_mail_wrapperthànhdrupal_mail_wrapperTham khảo:
Để ý đoạn (ở cả 2 bản):
<?phpif (variable_get('smtp_library', '') && file_exists(variable_get('smtp_library', ''))) {
// ...
}
?>
Thế Hồng
@ Thế Hồng
Cảm ơn bạn đã chỉ điểm. Mình có xem cái drupal_mail_send cho version 6, nhưng không thấy cái hướng dẫn nào cho phpmailer cả (mình không phải là PHP developer nên không có example thì....chết). Mình quyết định không sửa module nửa mà chọn mua host mới để tránh mất quá nhiều thời gian cho việc cài đặt Drupal.