Solved

Change Sender Name in Postfix?

Posted on 2008-10-22
4
4,085 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This article discusses how to implement server side field validation and display customized error messages to the client.
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 and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

752 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