Empty

Total: £0.00

Drupal Commons contact form does not work with SMTP module

By marksams, 06/06/2011 - 23:00

After a bit of reading about the details, formatting of messages, and security of SMTP servers, I found the answer I was looking for here. It looks like a small sacrifice has to be made in masking the sender's email address, and just using the site email address - but this was fine for me, and it works.

 

NOTE: The following fix/workaround requires editing a core module. This is not considered best practice - changes will be lost when upgrading Drupal, and you will need to re-implement this change if it is still applicable in the latest version.

 


  • To implement the fix/workaround, edit modules/contact/contact.pages.inc

    • Comment out the $from variable on line 222 as follows

      • drupal_mail('contact', 'user_mail', $to, user_preferred_language($account), $values/*, $from*/);
    • Comment out the $from variable on line 226 as follows

      • drupal_mail('contact', 'user_copy', $from, $language, $values/*, $from*/);

As you will see by the code comments in contact.pages.inc, lines 222 and 226 are in the personal contact page section. I repeated this fix on lines 132 and 136 in the site contact page section just for good measure.


  • To ensure the sender is still identified in the body of the message, edit modules/contact/contact.module

    • Add the following line before the 'break;' in the 'case 'page_copy' :' section of the 'Implementation of hook_mail' at the end of the module.

      • $message['body'][] = t("Reply email address for !name is !mail.", array('!name' => $params['name'], '!mail' => $params['mail']));
Tags: