Solved

Change Sender Name in Postfix?

Posted on 2008-10-22
4
3,930 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

912 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

19 Experts available now in Live!

Get 1:1 Help Now