Solved

Change Sender Name in Postfix?

Posted on 2008-10-22
4
3,864 Views
Last Modified: 2013-11-10
Hello,

We run a LAMP server running CentOS 5, Postfix 2.3.3, and PHP5.x   When our PHP scripts send out email with the PHP mail() function, users's receive the emails with a Sender of "Apache" in the From area of the email.

We would like to be able to change "Apache" to something else, and have the change be global so that all of our PHP scripts that use the mail() function (there are many of them) will have this same new Sender name.

Thank you in advance.

Karl Cox
0
Comment
Question by:karlcox
4 Comments
 
LVL 4

Accepted Solution

by:
urgoll earned 168 total points
ID: 22781648

Hello,
check out your php.ini file, in the section [mail function]. You probably have something like the following defined:

sendmail_path = /usr/sbin/sendmail -t -i

and pretty much all else commented out. So what happens is php's mail() function calls the sendmail binary (which is the mail injection command of postfix) and gives it the message. Because postfix doesn't trust local users, it discards the 'from' field and replaces it with the Linux userid of the calling process. In this case, it is 'Apache'.

What you need to do is make it use SMTP instead of the sendmail command. You will need to know the name of your SMTP server, which may be 'localhost' if your postfix is running as such. In the php.ini's [mail function] section, add:

SMTP = <your SMTP server hostname>
smtp_port = 25
sendmail_from = something@example.com


The first two options will make PHP talk to the SMTP server directly, which implicitely trusts the information given to it; the last option sets the default sender email address to use.

Hope this helps,
Christophe
0
 
LVL 19

Assisted Solution

by:bevhost
bevhost earned 166 total points
ID: 22782000
Use the headers to set the From Header and the -f to set the envelope address.

http://au.php.net/manual/en/function.mail.php

Example #2 Sending mail with extra headers.

The addition of basic headers, telling the MUA the From and Reply-To addresses:

<?php

$to      = 'nobody@example.com';

$subject = 'the subject';

$message = 'hello';

$headers = 'From: webmaster@example.com' . "\r\n" .

    'Reply-To: webmaster@example.com' . "\r\n" .

    'X-Mailer: PHP/' . phpversion();
 

mail($to, $subject, $message, $headers);

?>

Example #3 Sending mail with an additional command line parameter.

The additional_parameters parameter can be used to pass an additional parameter to the program configured to use when sending mail using the sendmail_path.

<?php

mail('nobody@example.com', 'the subject', 'the message', null,

   '-fwebmaster@example.com');

?>

Open in new window

0
 
LVL 23

Assisted Solution

by:Maciej S
Maciej S earned 166 total points
ID: 23909591
Do you want to change sender's email, or sender's "description"? (From: Sender's description <sender's@email>)
If you want to change email, you may do it directly in postfix:
Add to your main.cf:
canonical_maps = hash:/path/to/canonical_maps_file
Then, create /path/to/canonical_maps_file, and put there line:
current@address.to.change   new@address.you.want.to.have

Then run "postmap /path/to/canonical_maps_file" and "postfix reload".

If you want to change sender's description, you may want to change just this user's comment (assuming your user is named 'apache', you may do this with command: usermod -c "New description" apache).
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
Easy CSR creation in Exchange 2007,2010 and 2013
To show how to generate a certificate request in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Servers >> Certificates…
The viewer will learn how to dynamically set the form action using jQuery.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now