Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Drupal 编辑include/mail.inc,在那里添加我自己的SMTP设置_Drupal - Fatal编程技术网

Drupal 编辑include/mail.inc,在那里添加我自己的SMTP设置

Drupal 编辑include/mail.inc,在那里添加我自己的SMTP设置,drupal,Drupal,以下函数包含在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', ''))) { inclu

以下函数包含在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);

你能写下修改后的代码供我参考吗?

drupal\u mail\u send中的代码是drupal核心功能的一部分,不应直接更改,因为在更新drupal时,您的更改可能会被覆盖

对Drupal核心文件的修改通常被Drupal社区称为“黑客核心”,并且在很大程度上是安全的

Drupal已经有很多模块可以帮助您。见:

模块:

添加对使用PHPMailer库发送电子邮件的SMTP支持。 附带关于如何使用Google的详细配置说明 邮件服务器

模块:

此模块允许Drupal绕过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);