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);
你能寫下修改後的代碼以供我參考嗎?