Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I change the default from address for the php mail() function. I know I can do it on a per-send basis, but I'd like to change the default setting as well.

share|improve this question
up vote 0 down vote accepted

You can set that in php.ini with "sendmail_from".

From the php.ini:

; For Win32 only.
;sendmail_from =

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = /usr/sbin/sendmail -t

If you haven't got access to php.ini for some reason, you could set the following in a .htaccess file:

php_value sendmail_from

Note: you can't set sendmail_path in this way for security reasons. Source:

share|improve this answer

I have done this for our webmasters in the MTA (smtp server). If your MTA is postfix, you could use the sender_canonical_maps lookup table. From man 5 postconf:

sender_canonical_maps (default: empty) Optional address mapping lookup tables for envelope and header sender addresses. The table format and lookups are documented in canoni‐ cal(5).

   Example: you want to rewrite the SENDER address  "user@ugly.domain"  to
   "user@pretty.domain", while still being able to send mail to the RECIP‐
   IENT address "user@ugly.domain".

   Note: $sender_canonical_maps is processed before $canonical_maps.


   sender_canonical_maps = hash:/etc/postfix/sender_canonical

share|improve this answer

You need to define a header where you put "From: Toto toto < >" (without spaces, but the interface remove the contents of < >).

To change it in default setting, you should do this not in PHP, but in your MTA. Rewrite the from address to what you want.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.