Zend_Mail::addHeader PHP Method

addHeader() public method

Add a custom header to the message
public addHeader ( string $name, string $value, boolean $append = false ) : Zend_Mail
$name string
$value string
$append boolean
return Zend_Mail Provides fluent interface
    public function addHeader($name, $value, $append = false)
    {
        $prohibit = array('to', 'cc', 'bcc', 'from', 'subject', 'reply-to', 'return-path', 'date', 'message-id');
        if (in_array(strtolower($name), $prohibit)) {
            /**
             * @see Zend_Mail_Exception
             */
            require_once 'Zend/Mail/Exception.php';
            throw new Zend_Mail_Exception('Cannot set standard header from addHeader()');
        }
        $value = $this->_filterOther($value);
        $value = $this->_encodeHeader($value);
        $this->_storeHeader($name, $value, $append);
        return $this;
    }

Usage Example

 public function sendMail()
 {
     if (func_num_args() >= 4) {
         $to = func_get_arg(0);
         $from = func_get_arg(1);
         $subject = func_get_arg(2);
         $messageRecieved = func_get_arg(3);
         $tr = new Zend_Mail_Transport_Smtp($this->_host, array('auth' => 'login', 'username' => $this->_username, 'password' => $this->_password, 'port' => $this->_port));
         Zend_Mail::setDefaultTransport($tr);
         $mail = new Zend_Mail('utf-8');
         $mail->setFrom($from);
         $mail->setBodyHtml($messageRecieved);
         $mail->addTo($to);
         $mail->setSubject($subject);
         $mail->addHeader('MIME-Version', '1.0');
         $mail->addHeader('Content-Transfer-Encoding', '8bit');
         $mail->addHeader('X-Mailer:', 'PHP/' . phpversion());
         try {
             $mail->send();
             $response = "Mail sent";
             return $response;
         } catch (Exception $e) {
             throw new Zend_Controller_Action_Exception('SendGrid Mail sending error', 500);
         }
     } else {
         throw new Zend_Controller_Action_Exception('Paramter Not passed', 500);
     }
 }
All Usage Examples Of Zend_Mail::addHeader