Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

3 Answers 3

up vote 0 down vote accepted

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

From the php.ini:

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = me@example.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
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 you@example.com

Note: you can't set sendmail_path in this way for security reasons. Source: http://nl.php.net/manual/en/mail.configuration.php

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.

   Example:

   sender_canonical_maps = hash:/etc/postfix/sender_canonical

share|improve this answer

You need to define a header where you put "From: Toto toto < toto@toto.com >" (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

 
discard

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.