note 104594 modified in function.mail by danbrown

From: Date: Fri, 24 Jun 2011 15:28:08 +0000
Subject: note 104594 modified in function.mail by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-180918@lists.php.net to get a copy of this message
I've had all sorts of problems with scripts that don't set the "-f user@example.org" parameter when using mail() if postfix is the sendmail agent. In postfix I had SMTP relay authentication based on the sender address, but it was always the PHP user as the sender until I adapted the code from: <?php mail('test@example.org', 'Subject', 'Body', 'From: user@example.org'); ?> to: <?php mail('test@example.org', 'Subject', 'Body', 'From: user@example.org', '-f user@example.org'); ?> I couldn't find a way to adjust PHP or Postfix to do this for me, so I had to edit the application. I was actually using Zend_Mail_Transport_Smtp, which made it that little bit trickier. I ended up with this: <?php class My_Mail_Transport_Sendmail extends Zend_Mail_Transport_Sendmail { public function _sendMail() { if ($this->parameters === null) { $this->parameters = '-f ' . $this->_mail->getFrom(); } return parent::_sendMail(); } } ?> --was-- I've had all sorts of problems with scripts that don't set the "-f user@example.org" parameter when using mail() if postfix is the sendmail agent. In postfix I had SMTP relay authentication based on the sender address, but it was always the PHP user as the sender until I adapted the code from: <?php mail('test@example.org', 'Subject', 'Body', 'From: user@example.org'); ?> to: <?php mail('test@example.org', 'Subject', 'Body', 'From: user@example.org', '-f user@example.org'); ?> I couldn't find a way to adjust PHP or Postfix to do this for me, so I had to edit the application. I was actually using Zend_Mail_Transport_Smtp, which made it that little bit trickier. I ended up with this: <?php class My_Mail_Transport_Sendmail extends Zend_Mail_Transport_Sendmail { public function _sendMail() { if ($this->parameters === null) { $this->parameters = '-f ' . $this->_mail->getFrom(); } return parent::_sendMail(); } } http://php.net/manual/en/function.mail.php

« previous php.notes (#180918) next »