Otherwise mail headers are not friendly and expose server details.

In print_mail.inc function print_mail_mail() I added these lines which fixed it:

$message['headers']['From'] = 'info@example.com'
$message['headers']['Reply-To'] = 'info@example.com'

Of course, the values should be retrieved from the form dynamically. What I did is to save fld_from_addr and fld_from_name as globals in function print_mail_form_validate() and retrieve them in function print_mail_mail() - like this:

In function print_mail_form_validate() I did -

$custom_from_name = $form_state['values']['fld_from_name'];
$custom_from_address = $from_addr;

In function print_mail_mail() I did -

$message['headers']['From'] = $custom_from_name;
$message['headers']['Reply-To'] = $custom_from_address;

HOWEVER - Only the form_address works OK; the name is shown like this: the_expected_name@servername.domain.com

Could anyone help with this?

Comments

jcnventura’s picture

Title: In print_mail - ['headers']['From'] and ['headers']['Reply-To'] should be added » Use Reply-To field in Send to friend

The drupal_mail() function itself handles the From field, so that's probably why it's not working for you.. Your mail server is adding the domain to it because it's configured to do so.

The 'Reply-To' field however would be a good feature to add to the module. It's nice to know I'll have stuff to do for 1.8.

João

jcnventura’s picture

Status: Active » Closed (works as designed)

On the other hand, it seems that the reason why the 'Reply-To' field is not being set is because of a conscious decision by Drupal core developers not to do it. See #330084: Setting Reply-To in mails to the same as From is redundant..

Since I have to agree with them that there's no reason to add the 'Reply-To' field to the same value as the 'From' field, there's nothing I can do.

João

amir simantov’s picture

Hi João,

Thanks for the reply and giving a thought (and another one...)

I will have to think about it and will get back to you.

Amir

olbion’s picture

Not sure if this goes here. I did a little hack to make mail_print use Reply-To instead of From. The From address will be the site default, and the Reply-To whatever user sent the message's email. That way, the message appears to be from the website but if the receiver tries to reply, it will also work and go to the user who sent it. Also, I'm thinking that this would be a way to prevent mail from being considered spam. Ie, my server might not have the permission to send email from another users email. Not too sure about this though.

Anyway, here's what I did:

Line 297 of print_mail.inc:

        // @olbion: Set from to NULL to send from site default email instead; use Reply-To instead
        $params['Reply-To'] = $from;
        $from = NULL;

Then on line 350 I use the param from above to populate the headers that will be sent with the email:

      //@olbion: add Reply-To from params
      $message['headers']['Reply-To'] = $params['Reply-To'];

Hope this is useful to someone

Yuri’s picture

#olbion your #4 solution sound good, especially because Gmail flags all emails as spam, which are send with the 'send a friend' method.
My problem is that the code in print_mail.inc has changed a lot since your post, and I don't know how and where to insert it.
You are still using it this way?

jcnventura’s picture

Status: Closed (works as designed) » Fixed

I just changed this to a solution similar to the one in #4, as part of the fix for #1678180: Gmail flags the outgoing 'send by email' messages as spam.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.