Sent emails rejected by mail servers when using PHP mail()
LoneWolfPR - April 29, 2008 - 04:36
| Project: | Drupal |
| Version: | 6.2 |
| Component: | base system |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | duplicate |
Description
A member wasn't getting the verification email containing her password. I was at a loss because i checked my mail logs and it said yahoo bounced the mail. However it wasn't returned to my Admin email address. So I did some checking around in my servers mailboxes. It turns out the mail was bounced to www-data@lonewolf (lonewolf is the hostname of my server). I checked the headers in the returned email though and all the addresses seem to be my admin email. Somehow though the above is getting included. Any thoughts on how to fix this?
the message from Yahoo's system is:
<addressremoved@yahoo.com>: host f.mx.mail.yahoo.com[68.142.202.247] said: 501 Syntax
error in parameters or arguments (in reply to MAIL FROM command)
#1
ok. i found a work around. I went into the mail.inc file and edited this function:
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']),
join("\n", $mimeheaders)
);
}
}
I changed line after the line that reads "join("\n", $mimeheaders)" to:
join("\n", $mimeheaders),-fme@mydomain.com
obviously i've omitted my real email address, but this fixed the problem as it forced a Return_Path header to match my email address.
#2
More and more mail servers are rejecting emails without the proper return-path value. Not having this means a core Drupal file must be modified, as described by LoneWolfPR above. We just need a setting for return-path email sender added to the site configuration, and the problem will be solved.
#3
Marked this as a bug, since drupal_mail_send() doesn't send mail if you are using standard php mail() with PHP5 and sendmail rejects mails without sender.
Its no option to modify core files, a patch should be applied. Unfortunately I'm not able to create one here, but drupal_mail_send should look like
<?php
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),
'-f'. $message['headers']['From']
);
}
}
?>
Btw.: this applies for drupal7, too!
#4
subscribing
#5
subscribing
#6
Patch attached, please review.
#7
it is "always" desirable to be
$message['headers']['From']?#8
This is a duplicate of #131737: Return-Path overwritten by the PHP mail() function.