# Howto change email header in emails send from PHP

**URL:** <https://www.ruby-forum.com/t/howto-change-email-header-in-emails-send-from-php/195526>\
**Category:** NGINX\
**Created:** [September 24, 2010, 11:07am UTC](https://www.ruby-forum.com/t/howto-change-email-header-in-emails-send-from-php/195526 "2010-09-24T11:07:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![frocco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a87d85/32.png) [@frocco](https://www.ruby-forum.com/u/frocco)\
**Post date:** [September 24, 2010, 11:07am UTC](https://www.ruby-forum.com/t/howto-change-email-header-in-emails-send-from-php/195526/1 "2010-09-24T11:07:10Z")

</div>

Hello, all emails, which I send from PHP mail() have the header like:

Received: from nginx by localhost with local (Exim 4.63)  
(envelope-from [nginx@localhost](mailto:nginx@localhost))

How I can change the address to something like removed\_email\_address@domain.invalid there?

Thank You

---

<div class="post-metadata">

**Author:** ![frocco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a87d85/32.png) [@frocco](https://www.ruby-forum.com/u/frocco)\
**Post date:** [September 24, 2010, 11:21am UTC](https://www.ruby-forum.com/t/howto-change-email-header-in-emails-send-from-php/195526/2 "2010-09-24T11:21:48Z")

</div>

php code:  
mail(“removed\_email\_address@domain.invalid”,“subject”,“messagecontents”,“From:  
removed\_email\_address@domain.invalid”);

so, headers is a php issue, and can be set in php mail function.  
[http://php.net/manual/en/function.mail.php](http://php.net/manual/en/function.mail.php)

Bahattin,  
ehcp Developer

---

<div class="post-metadata">

**Author:** ![frocco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a87d85/32.png) [@frocco](https://www.ruby-forum.com/u/frocco)\
**Post date:** [September 24, 2010, 11:49am UTC](https://www.ruby-forum.com/t/howto-change-email-header-in-emails-send-from-php/195526/3 "2010-09-24T11:49:19Z")

</div>

I am using CakePHP framework, so I set this variables:  
$this-\>Email-\>from =  
Configure::read(‘Site.noreplyemail’);  
$this-\>Email-\>return =  
Configure::read(‘Site.noreplyemail’);  
$this-\>Email-\>replyTo=Configure::read(‘Site.noreplyemail’);  
where Configure::read(‘Site.noreplyemail’) is the email address

But this didnt changed all the address in header. The email header is  
below:

Delivered-To: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Received: by 10.204.121.3 with SMTP id f3cs5634bkr;  
Fri, 24 Sep 2010 02:43:02 -0700 (PDT)  
Received: by 10.100.154.3 with SMTP id b3mr3322700ane.245.1285321381720;  
Fri, 24 Sep 2010 02:43:01 -0700 (PDT)  
Return-Path: [nginx@mydomain](mailto:nginx@mydomain)  
Received: from mydomain ([mail.mydomain.com](http://mail.mydomain.com) [xxx.xxx.xxx.xxx])  
by [mx.google.com](http://mx.google.com) with ESMTP id  
d19si4617117and.113.2010.09.24.02.43.01;  
Fri, 24 Sep 2010 02:43:01 -0700 (PDT)  
Received-SPF: neutral ([google.com](http://google.com): xxx.xxx.xxx.xxx is neither  
permitted nor denied by best guess record for domain of  
nginx@mydomain) client-ip=xxx.xxx.xxx.xxx;  
Authentication-Results: [mx.google.com](http://mx.google.com); spf=neutral ([google.com](http://google.com):  
xxx.xxx.xxx.xxx is neither permitted nor denied by best guess record  
for domain of nginx@mydomain) smtp.mail=nginx@mydomain  
Received: from nginx by mydomain with local (Exim 4.63)  
(envelope-from [nginx@mydomain](mailto:nginx@mydomain))  
id 1Oz4o1-0000Bd-4h  
for [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid); Fri, 24 Sep 2010 09:43:01 +0000  
To: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Account Activation  
From: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Reply-To: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
X-Mailer: CakePHP Email Component  
Content-Type: text/plain; charset=UTF-8  
Content-Transfer-Encoding: 7bit  
Message-Id: [E1Oz4o1-0000Bd-4h@mydomain](mailto:E1Oz4o1-0000Bd-4h@mydomain)  
Sender: Nginx user [nginx@mydomain](mailto:nginx@mydomain)  
Date: Fri, 24 Sep 2010 09:43:01 +0000

2010/9/24 bvidinli [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> On Fri, Sep 24, 2010 at 12:06 PM, Frank R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > nginx mailing list  
> > [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

–  
FandaR-IT - Server administration and programming

> **[Index of /](http://fandar-it.com)**

MSN: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
ICQ: 217613557  
GTalk: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Yahoo: fandar2

---

<div class="post-metadata">

**Author:** ![frocco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a87d85/32.png) [@frocco](https://www.ruby-forum.com/u/frocco)\
**Post date:** [September 24, 2010, 2:17pm UTC](https://www.ruby-forum.com/t/howto-change-email-header-in-emails-send-from-php/195526/4 "2010-09-24T14:17:26Z")

</div>

those seems to be headers sent by your MTA, such as postfix.

set servername related parameters of postifx accordingly.

---

<div class="post-metadata">

**Author:** ![frocco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a87d85/32.png) [@frocco](https://www.ruby-forum.com/u/frocco)\
**Post date:** [September 24, 2010, 1:05pm UTC](https://www.ruby-forum.com/t/howto-change-email-header-in-emails-send-from-php/195526/5 "2010-09-24T13:05:26Z")

</div>

Hello!

On Fri, Sep 24, 2010 at 11:06:08AM +0200, Frank R. wrote:

> Hello, all emails, which I send from PHP mail() have the header like:
> 
> Received: from nginx by localhost with local (Exim 4.63)  
> (envelope-from [nginx@localhost](mailto:nginx@localhost))
> 
> How I can change the address to something like [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) there?

Hey, guys, it’s not PHP list. Please stop. Thank you.

Maxim D.

---

<div class="post-metadata">

**Author:** ![frocco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a87d85/32.png) [@frocco](https://www.ruby-forum.com/u/frocco)\
**Post date:** [September 24, 2010, 4:10pm UTC](https://www.ruby-forum.com/t/howto-change-email-header-in-emails-send-from-php/195526/6 "2010-09-24T16:10:25Z")

</div>

The problem is, that nginx is running under nginx user, so the email  
address is [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid), but how can I change it to  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) ?

2010/9/24 bvidinli [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > ```
> > $this->Email->replyTo=Configure::read('Site.noreplyemail');
> > 
> > ```
> > 
> > Received: from mydomain ([mail.mydomain.com](http://mail.mydomain.com) [xxx.xxx.xxx.xxx])  
> > id 1Oz4o1-0000Bd-4h  
> > Date: Fri, 24 Sep 2010 09:43:01 +0000
> > 
> > > Bahattin,
> > > 
> > > > Thank You  
> > > > [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)  
> > > > Yahoo: fandar2  
> > > > [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

–  
FandaR-IT - Server administration and programming

> **[Index of /](http://fandar-it.com)**

MSN: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
ICQ: 217613557  
GTalk: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Yahoo: fandar2

---

<div class="post-metadata">

**Author:** ![frocco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a87d85/32.png) [@frocco](https://www.ruby-forum.com/u/frocco)\
**Post date:** [September 24, 2010, 4:32pm UTC](https://www.ruby-forum.com/t/howto-change-email-header-in-emails-send-from-php/195526/7 "2010-09-24T16:32:40Z")

</div>

On 24 Set 2010 15h09 WEST, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The problem is, that nginx is running under nginx user, so the email  
> address is [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid), but how can I change it to  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) ?

Create an alias for your MTA.: man 5 aliases

For example:

echo ‘nginx: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)’ \>\> /etc/aliases

Reload MTA. Done.

— appa
