Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By smooshy on
Has anyone successfully used PEAR to send mail instead of sendmail or smtp? My host doesn't allow for sending mail except through the PEAR modules.
Comments
Found it
It's easier than I thought in Drupal 5.x. I created a pearmail.inc and copied that to includes/ and then added smtp_library conf in settings.php to point to pearmail.inc.
Thanks for posting your
Thanks for posting your solution. Very elegant.
It's great when people come back to share what works.
me too me too
You can see a more detailed explanation here
bug fix
@nirl's solution that he links to in the previous comment is good and works for me. But we had one obscure problem with it.
These two header values (coming from Drupal) were causing our ISP to reject our send-attempt:
I think it's because the "name" part of the email address looks like a mal-formed email address. By forcing it to
Foobooks Com <info@foo-books.com>
or"Foo-books.com" <info@foo-books.com>
, then it the SMTP server honours the request and sends the email.So we look through the headers, and insert quotes if necessary, to make it look like this:
To implement this fix, insert the following code snippet in the smtpmail.inc file (which @nirl suggests creating) after the headers are set, and before you do the actual send.
In drupal 6.x
As said in nirl's link this solution only works in drupal 5.x. This is a fix to pearmail.inc for drupal 6.x:
<?php
require_once 'Mail.php';
require_once 'PEAR.php';
function drupal_mail_wrapper($message) {
global $smtpmail;
$to = $message['to'];
$from = $message['from'];
$subject = $message['subject'];
$headers = $message['headers'];
$body = $message['body'];
$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;
}
Fix for Drupal 7?
Is there any one who could help me with a fix for Pears MAIL:FACTORT in Drupal 7? I've tried to follow the instructions, but it feels like there's a difference between D6 and D7...