The changes in the function mimemail_headers means that the $sender variable is no longer added to the headers for the mail function.

To fix, I added a check for empty header fields: (sorry, not sure how to make a patch quickly)

  // Overwrite standard headers.
  if ($from) {
    if ( empty($headers['From']) || $headers['From'] == $default_from) {
      $headers['From'] = $from;
    }
    if ( empty($headers['Sender']) || $headers['Sender'] == $default_from) {
      $headers['Sender'] = $from;
    }
    // This may not work. The MTA may rewrite the Return-Path.
    if (empty($headers['Return-Path']) || $headers['Return-Path'] == $default_from) {
      preg_match('/[a-z0-9\-\.]+@{1}[a-z0-9\-\.]+/i', $from, $matches);
      $headers['Return-Path'] = "<$matches[0]>";
    }
  }

Comments

sgabe’s picture

Priority: Major » Normal
Status: Active » Needs review
StatusFileSize
new1.54 KB

Checking only for an empty value will throw an error if the header field is not set at all.

Enideo’s picture

Yes, you're right about the use of isset instead of empty, I wasn't thinking very thoroughly.

However your patch doesn't seem to match the original code in 6.x-1.0.

sgabe’s picture

Status: Needs review » Needs work

Yeah I think we won't gain much from using a separate function in this case (but would be nicer this way) so it is enough if we just simply add a check for empty().

sgabe’s picture

Status: Needs work » Needs review
StatusFileSize
new1.06 KB

Attaching new patch.

Enideo’s picture

Hey sgabe, thanks for all the help by the way :)

Your patch is still from the dev version, but I'm using the 6.x-1.0 version. However perhaps my bug report isn't necessary, as you've already got the isset() in the dev version available for download:

// in 6.x-1.0
    if ($headers['From'] == $default_from) {
// in 6.x-dev
    if (!isset($headers['From']) || $headers['From'] == $default_from) {

I believe the code in the dev version also fixes my issue, so using empty() may not be necessary. If you agree, then you can close this issue.

Perhaps I should've looked at the dev code first, but I'm trying to avoid all non production-ready code. Maybe you could do a mini-rollout of a new version with this fix, as the current 6.x-1.0 'production version' still has this bug in it. Of course I'm not sure how stable the rest of the code in dev module is, so I'll leave you to judge what to push forward..

sgabe’s picture

Status: Needs review » Closed (duplicate)

You should always check the development snapshot before opening a new issue. I thought you have encountered this scenario when the Sender field is set to an empty value...

I am marking this as a duplicate of #1391680: Headers not correctly set.

hukefung’s picture

Hello , do you know how many parameters in $headers array? and what are they. thanks.

hukefung’s picture

hi, guys , who could tell me that how different between $headers['From'] and $headers['Sender'], Cos I want to use the user typed address instead of the 'smtp_fromname' address of System Configuration for 'from' displaying in the email. Thanks.