2

I'm using the PHP Pear Mail_Mime library to send email. In my script, I set the "From:" header before sending the message. This all works fine on a server running Mac OS X, (which presumably uses sendmail as the mailer, although I'm not 100% sure.) When sending a test email, the "From:" field shows the correct sender.

However, if I run the same script on a Linux server with Exim4 as the mailer, the email is still sent but the "From:" header shows up as a default instead of the one I specified in the script.

I've tried setting the "-f [from email address]" option in the "additional parameters" for PHP's mail function, but this seems to have no effect.

Can anyone tell me how I might get the from header to work properly with Exim?

Any advice is greatly appreciated.

Cheers, Tom

EDIT: here's the code in case anyone is interested in looking at it.


<?php

  include_once('Mail.php');
  include_once('Mail/mime.php');


  $subject = "mime mail test";
  $from = "wtf@domain.com";
  $to = "wtf@domain.com";
  $visitor_email = $from;

  $message = new Mail_mime();
  $message->setTXTBody("hallo there!");


  $body = $message->get();
  $extraheaders = array("From"=>$from, "Subject"=>$subject,"Reply-To"=>$visitor_email);
  $headers = $message->headers($extraheaders);

  $mail = Mail::factory("mail");
  $result = $mail->send($to, $headers, $body, "", "-f wtf@domain.com -r wtf@domain.com");

  print_r($result);

?>



Tom
  • 18,685
  • 15
  • 71
  • 81
  • 1
    Try setting the `Return-path` header explicitly to the same one as reply-to and/or from. Also `Mail::send` only supports the first 3 arguments youre supplying assuming that is the PEAR Mail class youre using. – prodigitalson Dec 28 '10 at 01:37
  • Ah, thanks--I didn't realize that about the PEAR mail class. – Tom Dec 28 '10 at 01:43
  • Turns out this is a duplicate of http://stackoverflow.com/questions/4663040/from-email-address-changes-after-email-is-sent-gmail-postfix-relay/ – dkarp Jan 14 '11 at 20:33

1 Answers1

4

You're sending via the command line (vs. SMTP). Exim only allows trusted senders to use the -f option. Either:

  • Change it to use SMTP (which will allow you to use whatever sender you want provided you are allowed to send email at all (which usually means IP-based or authentication-based controls)
  • Send from a user that is trusted (like root or the exim user)
  • Add the user sending the mail to the trusted user list in the exim config, which would look something like this:

    trusted_users = root:apache:www:exim:60001

jj33
  • 7,543
  • 2
  • 38
  • 42
  • I tried both the trusted_users approach and also switching to SMTP, but the problem persists. I think I may have discovered the issue though, which is that exim is configured to send email via GMail, and apparently set up to send all email as one user. However, I'm still not sure what needs to be changed to fix the issue. Still, thanks very much for the info. – Tom Dec 28 '10 at 18:59
  • Please see http://stackoverflow.com/questions/4663040/from-email-address-changes-after-email-is-sent-gmail-postfix-relay/4673989#4673989 – dkarp Jan 14 '11 at 20:33