its not a common problem, but i think it deserves a posting

Problem

Mails - password, feedback, whatever - are not sent by the drupal installation 4.5/4.6, but no error occurs

Reason

Some providers have set up a special requirement to use the sendmail function (mostly used by the php mail(); function)

There needs to be a parameter -f + emailadress to successfully send an email through php

Solution

Look into the modules/user.module for function user_mail and this code

    return mail(
      $mail,
      mime_header_encode($subject),
      str_replace("\r", '', $message),
      "MIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8; format=flowed\nContent-transfer-encoding: 8Bit\n" . $header
    );

you need to add "-f from@example.com" so it looks like

    return mail(
      $mail,
      mime_header_encode($subject),
      str_replace("\r", '', $message),
      "MIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8; format=flowed\nContent-transfer-encoding: 8Bit\n" . $header,
      "-f from@example.com"
    );

do not miss the single , behind $header

for the emailaddress you can use whatever valid email you like

There is a small problem with this solution too, ALL emails sent by drupal will get this "from" adress.

If there are enough users with this problem id like to see a feature request for adding additional email parameters.

-micha
work in progress langmi.de

Comments

thealien’s picture

finaly I found the answer to my problem, thanks a lot micha.. I'm using drupal 4.7.0 beta6 and I couldn't send/receive mails.. there was no error nothing, and I tried this and now it works!

would like to see a fix in the future, so I don't have to manually change the module whenever I upgrade

___________________
my drupal site: http://www.wi-cn.com - Wireless Computer Networks

ajwwong’s picture

Also, make sure that the from email address aligns with what your site's actual email address.

Albert
www.ithou.org

and, btw, +1 on a fix to the core, somehow...

For reference, people may read the following below -- correspondence between Siteground.com and myself as we troubleshoot this error:

	
The php mail() function on Siteground does not send mail that is sent when the sender's email address ends in yahoo.com. Please fix this and eliminate the other filters that prevent the mail() function from operating as it should. The site is BROKEN without the full functioning of the php mail() command.


2006-05-16 01:06am by Alan -	Hello,

Could you tell us the name of the script that is causing the problem so that we can further investigate the issue? The mail() function works properly with the rest of the sites hosted on the same server and we haven't actually received any other complaints about it.

Thank you.

Best Regards,

Alan Karlson
System Administrator
www.SiteGround.com


2006-05-16 02:41am by ithou -	The script is in the drupal core:

user.module -- which is located here in my site:

www.ithou.org/modules/user.module

and the function in question within the module is

user_mail()

starting at line 408, as listed below in full.

Thank you for your attention.
--------------------------------------------
function user_mail($mail, $subject, $message, $header) {
if (variable_get('smtp_library', '') && file_exists(variable_get('smtp_library', ''))) {
include_once './' . variable_get('smtp_library', '');
return user_mail_wrapper($mail, $subject, $message, $header);
}
else {
/*
** Note: if you are having problems with sending mail, or mails look wrong
** when they are received you may have to modify the str_replace to suit
** your systems.
** - \r\n will work under dos and windows.
** - \n will work for linux, unix and BSDs.
** - \r will work for macs.
**
** According to RFC 2646, it's quite rude to not wrap your e-mails:
**
** "The Text/Plain media type is the lowest common denominator of
** Internet e-mail, with lines of no more than 997 characters (by
** convention usually no more than 80), and where the CRLF sequence
** represents a line break [MIME-IMT]."
**
** CRLF === \r\n
**
** http://www.rfc-editor.org/rfc/rfc2646.txt
**
*/
return mail(
$mail,
mime_header_encode($subject),
str_replace("\n", '', $message),
// str_replace("\r", '', $message),
"MIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8; format=flowed\nContent-transfer-encoding: 8Bit\n" . $header
);
}
}


2006-05-16 03:27am by kenny -	Hello,

The problem comes from the fact that you are trying to forge the From: header of the e-mail -- since recently, our MTAs do not allow such e-mails to go through. You can rectify this issue by replacing the From: address to be an e-mail address on a local domain (ithou.org or any of your sub-domains). You can still use the Reply-to: header.

Please do not hesitate to contact us again if you have any other questions or comments.

Best Regards,

Kenny
Support Team Manager
SiteGround.com



2006-05-16 10:18am by ithou -	Kenny,

Hi. Thank you for your note.

I have worked around the MTA forge filter by changing $header into

$header, "-f community@ithou.org"

Please note that since user.module is part of drupal core, you should definitely let people know about your MTA "forge" filter, if they are using drupal on your site. It otherwise renders the user_mail function of drupal rather useless until the above fix is manually added in the code.

Sincerely,
Albert
ajwwong’s picture

Now, they only block mails sent with a "from address" from known banks and financial institutions.

Albert
www.ithou.org