编辑mail.inc以启用SMTP服务器以发送邮件

时间:2012-03-20 22:46:03

标签: drupal

我想将以下代码放入Drupal7的include / mail.inc中,以便我可以从SourceForge的项目网站空间发送邮件。不要求我安装SMTP身份验证支持,我无法访问php.ini,我想知道这些代码应该放在哪里?提前谢谢!

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);

1 个答案:

答案 0 :(得分:0)

如果此代码可以成功发送没有drupal7的电子邮件(你必须确保它) 然后你可以用三种方式做到这一点:

  1. 编写drupal 7模块,将mail.php复制到* .module中,并将其余代码作为函数,这就像drupal手册一样。
  2. 只需将所有代码复制到你的theme / page.tpl.php,然后直接运行,有点脏
  3. hack drupal core,include / mail.inc,只是更改函数drupal_mail_send