I've gone through all the related forums and then some on this subject and just cannot seem to get anything straight, so I welcome any new directions....

I have a site that is working fine with the SMTP module and google apps as my smtp server. For mail volume increases we want to switch to authsmtp.com (a smtp service) that handles larger quotas than google apps currently allows. Anyhow, they require the mail from the site (contact forms and user-to-user communications) to be from a known address (i.e. the site's default - webmaster@site.com) and the reply-to to be set as what the user put into the from field.

From what I can gather this is the default for drupal?

But yet, no matter what settings I make in our php files, within postfix, using the SMTP module and the from address - everything still goes out with the from as what the user puts in the from field on the contact form.

Any ideas on how to get this set correctly?

Comments

Chad_Dupuis’s picture

oh and I should add that the google apps appears to work because it pays more attention to (from what I can tell) the return-path argument which is set correctly. So it allows users from @yahoo, or @hotmail to send through the form and be designated as the from and the reply-to address. More restrictive ISP's and authsmtp.com who we are planning to go with do not allow this....

Chad_Dupuis’s picture

Well I figured this out and am posting what I've did as it looks like this type of functionality is only on it's way into version 7. And, thanks immensely to the post at http://drupal.org/node/193914 which pretty much answered all of my questions - I just changed one thing as the user copy wouldn't work the way that post is laid out.

I was going to roll a patch off the latest 5 for this to make it easier for people, but I also have my contact module patched with the fix for anonymous users contacts, so not everyone will want that. I've included a copy of the patch file, though, as all the logic is really obvious...

+++ contact.module	2009-01-29 20:48:45.000000000 -0500
@@ -418,10 +418,17 @@ function contact_mail_user_submit($form_
   // Prepare all fields:
   $to = $account->mail;
   if ($user->uid) {
-    $from = $user->mail;
+//    $from = $user->mail;
+// Changed To Set Proper From and Reply-To And Add New Variable For User Copy
+	$usercopy = $user->mail;
+	$from = variable_get('site_mail','');
+	$headers = array('Reply-To' => $user->mail);
   }
   else {
-    $from = $form_values['mail'];
+//    $from = $form_values['mail'];
+// Changed To Set Proper From and Reply-To
+	$from = variable_get('site_mail','');
+	$headers = array('Reply-To' => $form_values['mail']);
   }
 
   // Format the subject:
@@ -431,11 +438,14 @@ function contact_mail_user_submit($form_
   $body = implode("\n\n", $message);
 
   // Send the e-mail:
-  drupal_mail('contact-user-mail', $to, $subject, $body, $from);
-
+//  drupal_mail('contact-user-mail', $to, $subject, $body, $from);
+//  Changed To Add Headers
+	drupal_mail('contact-user-mail', $to, $subject, $body, $from, $headers);
   // Send a copy if requested:
   if ($form_values['copy']) {
-    drupal_mail('contact-user-copy', $from, $subject, $body, $from);
+//    drupal_mail('contact-user-copy', $from, $subject, $body, $from);
+//  Changed To Add Headers
+    drupal_mail('contact-page-copy', $from, $subject, $body, $from, $headers);
   }

Cheers,

-Chad.
Yin Yang House Media Services Group

ferrangil’s picture

I just applied it but the emails I receive are still missing the Reply-To header, and thus, clicking reply as normally wouldn't send the email to the one who wrote the original form on the drupal site.
I'll keep looking for a solution...

EDIT: I finally found what needs to be added. You added the code for the User contact form, but I was looking (also) for the general site contact form, that is found on the contact_mail_page_submit function, not contact_mail_user_submit.

Finally, I would be able to replace user emails just be clicking Reply!!

Chad_Dupuis’s picture

I'm glad to hear you have it working. That's strange you had to edit the site wide form, that has always worked for me without any changes... oh well...

Chad_Dupuis’s picture

In drupal 6 you can use hook_mail_alter to change the information within a particular module (or globally if you build your own module) to correct this issue. My code for d6 to correct mails from the contact module is as follows (add the following to the end of contact.pages.inc)

+
+function contact_mail_alter(&$message) {
+	$properfrom = variable_get('site_mail','');
+        $properreplyto = $message['from'];
+	$message['headers']['From'] = $properfrom;
+        $message['headers']['Reply-To'] = $properreplyto;
+}
michaelcrm’s picture

Chad_Dupuis, I love you man! Your lines saved me out!

handsofaten’s picture

thank you so much. this ended a nightmare for me.