emaildrupaldrupal-contact-form

Email sent using contact form displays admins "from" address, and not the visitors email


This page uses Drupals contact form to send emails: http://www.westlake.school.nz/contact

Problem is, the school staff use outlook. When they recieve email from parents etc, the email comes in as

"From: admin@example.com On Behalf Of Westlake Boys High School"

In Gmail it comes in correctly such as

from Westlake Boys High School parentsEmailAddress@yahoo.com

Unfortunately, I cannot tell the entire school staff to stop using Outlook and exchange.

Can Drupals drupal_mail function be altered in order to fix this?

From contact.pages.inc:

drupal_mail('contact', 'page_mail', $contact['recipients'], language_default(), $values, $from);

Solution

  • tmsimont explains on this URL (http://api.drupal.org/api/function/drupal_mail#comment-3243) that

    the $from parameter will only alter the From header, not the Sender, Errors-to or Return-Path.

    of the drupal_mail function that is used by contact_mail_page_submit.

    with more details (code from the drupal_mail() function)

    line 3 - $default_from = variable_get('site_mail', ini_get('sendmail_from'));
    
    line 9 -     'from'     => isset($from) ? $from : $default_from,
    
    line 23 -  if ($default_from) {
    line 24 -    // To prevent e-mail from looking like spam, the addresses in the Sender and
    line 25 -    // Return-Path headers should have a domain authorized to use the originating
    line 26 -    // SMTP server. Errors-To is redundant, but shouldn't hurt.
    line 27 -    $headers['From'] = $headers['Sender'] = $headers['Return-Path'] = $headers['Errors-To'] = $default_from;
    line 28 -  }
    line 29 -  if ($from) {
    line 30 -    $headers['From'] = $from;
    line 31 -  }
    line 32 -  $message['headers'] = $headers;
    

    So to solve your problem you could implement hook_mail function (http://drupal.org/node/358855#comment-2079266)

    More resources can be found here:

    1 - http://drupal.org/node/656472

    2 - http://drupal.org/node/861562

    3 - http://www.nmglc.co.uk/content/overriding-drupals-mail-function