PEAR::Mail
with drupal_mail_wrapper
.- Install PEAR::Mail. On linux you can just run the following command as root:
pear install --alldeps Mail
- Create a new file, say
includes/smtpmail/smtpmail.inc
and paste the following code into it:
<?php
require_once 'Mail.php';
require_once 'PEAR.php';
function drupal_mail_wrapper($mailkey, $to, $subject, $body, $from, $headers) {
global $smtpmail;
$headers['From'] = $from;
if ( empty($headers['To'])) {
$headers['To'] = $to;
}
$headers['Subject'] = $subject;
$recipients = $to;
$mail_object =&Mail::factory('smtp', $smtpmail);
$output = $mail_object->send($recipients, $headers, $body);
return $output;
} - Edit your
settings.php
and add the following at the end:
$conf = array(
'smtp_library' => 'includes/smtpmail/smtpmail.inc'
);
global $smtpmail;
$smtpmail= array();
$smtpmail["host"] = 'your.mail.host';
$smtpmail["auth"] = TRUE;
$smtpmail["username"] = 'your_user_name';
$smtpmail["password"] = 'your_password';
From now on every call to
drupal_mail
will go through your drupal_mail_wrapper
and will be sent using PEAR::Mail with SMPT authentication. I'm sure some more serious drupaler would have made this a nice module, with configuration screens and the lot, but I'm too lazy today.