2012-04-18 55 views
0

Drupal6的include/mail.inc中包含以下函數,它使用埋在名爲「php.ini」的文件中的默認SMTP設置來發送郵件。編輯include/mail.inc,在那裏添加我自己的SMTP設置

function drupal_mail_send($message) { 
    // Allow for a custom mail backend. 
    if (variable_get('smtp_library', '') && file_exists(variable_get('smtp_library', ''))) { 
    include_once './'. variable_get('smtp_library', ''); 
    return drupal_mail_wrapper($message); 
    } 
    else { 
    $mimeheaders = array(); 
    foreach ($message['headers'] as $name => $value) { 
     $mimeheaders[] = $name .': '. mime_header_encode($value); 
    } 
    return mail(
     $message['to'], 
     mime_header_encode($message['subject']), 
     // Note: e-mail uses CRLF for line-endings, but PHP's API requires LF. 
     // They will appear correctly in the actual e-mail that is sent. 
     str_replace("\r", '', $message['body']), 
     // For headers, PHP's API suggests that we use CRLF normally, 
     // but some MTAs incorrecly replace LF with CRLF. See #234403. 
     join("\n", $mimeheaders) 
    ); 
    } 
} 

但我使用共享的主機,所以我不能編輯php.ini文件,我想修改上面的函數「drupal_mail_send」,下面添加代碼到該功能,以便它可以繞過PHP郵件( )功能,並直接發送電子郵件到我最喜歡的SMTP服務器。

include('Mail.php'); 

$recipients = array('[email protected]'); # Can be one or more emails 

$headers = array (
    'From' => '[email protected]', 
    'To' => join(', ', $recipients), 
    'Subject' => 'Testing email from project web', 
); 

$body = "This was sent via php from project web!\n"; 

$mail_object =& Mail::factory('smtp', 
    array(
     'host' => 'prwebmail', 
     'auth' => true, 
     'username' => 'YOUR_PROJECT_NAME', 
     'password' => 'PASSWORD', # As set on your project's config page 
     #'debug' => true, # uncomment to enable debugging 
    )); 

$mail_object->send($recipients, $headers, $body); 

你能寫下修改後的代碼以供我參考嗎?

回答

0

drupal_mail_send中的代碼是Drupal核心功能的一部分,不應直接更改,因爲更新Drupal時可能會覆蓋您的更改。

Drupal核心文件的修改通常被Drupal社區稱爲「黑客核心」,主要是discouraged

Drupal已經有一些可用的模塊可以幫助你。請參閱:

http://drupal.org/project/phpmailer模塊:

發送使用PHPMailer的庫電子郵件再添SMTP支持。 附帶詳細配置說明,瞭解如何使用Google郵件服務器的 Mail。

http://drupal.org/project/smtp模塊:

這個模塊允許Drupal的繞過PHP mail()函數,直接發送電子郵件 到SMTP服務器。

相關問題