Download & Extend

Sent emails rejected by mail servers when using PHP mail()

Project:Drupal core
Version:6.2
Component:base system
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (duplicate)

Issue Summary

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)

Comments

#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

Title:Account Verification email rejected by Yahoo, but I think I found the source of the problem.» Sent emails rejected by mail servers when using PHP mail()
Version:6.1» 6.2
Category:support request» feature request

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

Component:user system» base system
Category:feature request» bug report

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

Status:active» needs review

Patch attached, please review.

AttachmentSizeStatusTest resultOperations
mail_f_option.patch444 bytesIgnored: Check issue status.NoneNone

#7

it is "always" desirable to be $message['headers']['From']?

#8

nobody click here