Hi,

[This is a 6.x question but this should apply to prior versions by degree.]
I had a search/google for this question and should have been able to find it as a few hosts are insisting on the -f parameter for mail(. Sorry if I missed your answer, but could you point me at it please.

My host needs to see the "from" option used in Drupal before the mail.inc function "drupal_mail_send" is allowed to send mail.
From what I can see:

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']),
join("\n", $mimeheaders)
);

The fifth '-f' parameter 'from' isn't passed I think.
I would like to pick up the drupal e-mail address from the site config but my PHP programming isn't so good; my programming days were a while ago and on MS but I wouldn't mind getting back into it on OSS.

Where do I pick up that variable/function result in this module please? I tried to look for the function myself and didn't find it listed as a global variable.

Thanks in advance.

Comments

borisbuzzman’s picture

I wasn't getting the mail that drupal sends out until I added:
"-fuser@domain.com"

before the final close bracket, but I'd like to add it without, Ugh, hard coding!!

borisbuzzman’s picture

--- mail.inc.orig 2008-01-25 17:04:00.000000000 +0000
+++ mail.inc.new 2008-04-05 20:35:52.991525652 +0100
@@ -181,13 +181,19 @@ function drupal_mail_send($message) {
foreach ($message['headers'] as $name => $value) {
$mimeheaders[] = $name .': '. mime_header_encode($value);
}
+
+ // added 5.4.08
+ // fasthosts needs -f parameter
+ $from = variable_get('site_mail', ini_get('sendmail_from'));
+
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']),
- join("\n", $mimeheaders)
+ join("\n", $mimeheaders),
+ "-f$from"
);
}
}

as I said I haven't ever coded in php before but I'm sure that $from can be put inline. Personally I can't see this every doing any harm so why can't it be put in the core source.
I found that the "default_from" variable in the top half of the mail include is blank so it wasn't helpful.

redpuma’s picture

Fantastic these changes immediately solved the Fasthosts problems we had.

rebaths’s picture

Could someone explain this solution to me? I am new to drupal and php in general and am not sure how to implement this fix.

I have Drupal 6.13 and when users register, they never receive the confirmation email with initial password!

rebaths’s picture

Bump.. please someone help!

transition’s picture

we are having the same problem as above, could someone please help with instructions on the above fix for us php newbies?

Thanks for any light you can shed our way! :-)

redpuma’s picture

This makes it work on Fasthosts hosting setup.

Although you should not edit the core this is done to solve the issue on that hosting platform

The file you need to edit is drupal/install/mail.inc

you add the lines with a "+" and remove those with a "-"

the original code for the function looked like this

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

then would look like this..

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);
    }
     // added 5.4.08
     // fasthosts needs -f parameter
     $from = variable_get('site_mail', ini_get('sendmail_from'));

    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),
      "-f$from"
    );
  }
}

At least I think that's what I did.

vitis’s picture

Welcome emails stopped working this morning.
see
http://drupal.org/node/316287
http://www.ubercart.org/forum/support/14578/emails_stopped_sending_cart
http://drupal.org/node/660084
http://drupal.org/node/466072

UPDATE: My email problem seems to be due to Comcast; they resolved it.