Set up Email cho Drupal

Events happening in the community are now at Drupal community events on www.drupal.org.
investing's picture

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: Only local images are allowed.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

Comments

Có lẽ phải nhờ tech

thehong's picture

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

investing's picture

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ể

thehong's picture
  1. Thay thể
    <?php
    include_once '/sites/includes/class.phpmailer.php'; // Noi de module phpmailer
    ?>

    thành
    <?php
    include_once base_path () . '/sites/includes/class.phpmailer.php'; // Noi de module phpmailer
    ?>
  2. Thay tên hàm user_mail_wrapper thành drupal_mail_wrapper
  3. Tham số cho drupal_mail_wrapper đối với
    • Drupal 5: là drupal_mail_wrapper($mailkey, $to, $subject, $body, $from, $headers);
    • Drupal 6: là drupal_mail_wrapper($message);

Tham khảo:

Để ý đoạn (ở cả 2 bản):

<?php
 
if (variable_get('smtp_library', '') && file_exists(variable_get('smtp_library', ''))) {
   
// ...
 
}
?>

Thế Hồng

@ Thế Hồng

investing's picture

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.

mình cài drupal 7 trên

duwenxiao's picture

mình cài drupal 7 trên byethost và cũng gặp lỗi tương tự. Mình không phải dân IT nên việc đụng vào code là rất hãi hùng. Bạn nào có các nào khắc phục lỗi trên dễ dàng hơn không mách mình với. Cảm ơn nhiều!

free host byehost không hổ trợ gởi email

Shellingfox's picture

Cách đơn giản nhất là bạn cài thêm module smtp: http://drupal.org/project/smtp
Bật module này lên và sau đó vào phần cấu hình ở Configuration » System » SMTP Authentication Support nhập các tham số của smtp vào (Có thể sử dụng SMTP của google).

--
Best regards,
Sang, Lê Thanh

Tel: +84 988079498
Email: me[at]sanglt.com
WWW: www.sanglt.com

Dùng SMTP module with Godaddy hosting

tqnghiep's picture

Chào các sư huynh,

Có ai đã dùng hosting Godaddy chưa xin mách em với, em dùng module smtp ở các hosting khác và ở local thì chạy good, but upload lên Godaddy hosting lại chạy không được.

Bằng cách mà em cấu hình smtp & pop3 trên gmail, outlook(thì ok, gửi & nhận mail không vấn đề gì) em dùng SMTP server đó cấu hình cho module smtp lại die.

Error:

  • warning: fsockopen() [function.fsockopen]: unable to connect to ssl://smtpout.secureserver.net:465 (Connection refused) in [sitename]/sites/all/modules/smtp/phpmailer/class.smtp.php on line 122.
  • warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in [sitename]/sites/all/modules/smtp/phpmailer/class.smtp.php on line 122.
  • warning: fsockopen() [function.fsockopen]: unable to connect to ssl://:465 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in [sitename]/sites/all/modules/smtp/phpmailer/class.smtp.php on line 122.

SMTP server:Mailbox msg: Incoming (POP3) server: pop.secureserver.net Outgoing (SMTP) server: smtpout.secureserver.net
Mail address: Là địa chỉ mail được tạo từ hosting: ex: info@sitename.com
Port & SSL: Em thử với nhiều cách dùng port 25, ssl = true or false đều không đc.

Giúp em với, thnk so much.

TQN

Hình như không phải, trước em

luatviettin's picture

Hình như không phải, trước em dùng PA việt nam cũng dính, hóa ra các bố ấy cấm phpmail nên chịu ! Hay dùng module sendmail via SMTP xem sao ! lúc nào cũng an toàn vì nó cho mình 50mail / ngày !