Solved

Change Sender Name in Postfix?

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What if i make webbased alternative for MS Access 5 71
PHP 5.6 and 7.x 4 23
Checking https returns 301 21 30
Exchange2013 MAPI 6 17
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
As cyber crime continues to grow in both numbers and sophistication, a troubling trend of optimization has emerged over the last year.
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…

830 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