以下函数包含在 Drupal6 的 include/mail.inc 中,它使用埋在名为“php.ini”的文件中的默认 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 mail() 函数并直接发送电子邮件到我最喜欢的 SMTP 服务器。
include('Mail.php');
$recipients = array( 'someone@example.com' ); # Can be one or more emails
$headers = array (
'From' => 'someone@example.com',
'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);
你能写下修改后的代码供我参考吗?