[Solar-svn] Revision 2881

pmjones at solarphp.com pmjones at solarphp.com
Wed Oct 17 08:11:35 CDT 2007


Solar_Mail_Message: [ADD] Methods setReplyTo() and getReplyTo(), for easier "Reply-To:" header.


Modified: trunk/Solar/Mail/Message.php
===================================================================
--- trunk/Solar/Mail/Message.php	2007-10-17 13:03:13 UTC (rev 2880)
+++ trunk/Solar/Mail/Message.php	2007-10-17 13:11:34 UTC (rev 2881)
@@ -141,6 +141,15 @@
     
     /**
      * 
+     * The "Reply-To:" address and display-name.
+     * 
+     * @var array
+     * 
+     */
+    protected $_reply_to = array('', '');
+    
+    /**
+     * 
      * The "Return-Path" value.
      * 
      * @var string 
@@ -328,7 +337,7 @@
      * 
      * Returns the "From:" address for this message.
      * 
-     * @return string
+     * @return array
      * 
      */
     public function getFrom()
@@ -338,6 +347,41 @@
     
     /**
      * 
+     * Sets the "Reply-To:" on this message.
+     * 
+     * Strips CR/LF from the address and name to help avoid header injections.
+     * 
+     * @param string $addr The email address of the sender.
+     * 
+     * @param string $name The display-name for the sender, if any.
+     * 
+     * @return Solar_Mail_Message This object.
+     * 
+     */
+    public function setReplyTo($addr, $name = '')
+    {
+        $this->_reply_to = array(
+            $addr,
+            $name,
+        );
+        
+        return $this;
+    }
+    
+    /**
+     * 
+     * Returns the "Reply-To:" address for this message.
+     * 
+     * @return array
+     * 
+     */
+    public function getReplyTo()
+    {
+        return $this->_reply_to;
+    }
+    
+    /**
+     * 
      * Adds a "To:" address recipient.
      * 
      * @param string $addr The email address of the recipient.
@@ -638,6 +682,15 @@
         }
         $headers[] = array("From", $value);
         
+        // Reply-To: (optional)
+        if ($this->_reply_to[0]) {
+            $value = "<{$this->_reply_to[0]}>";
+            if ($this->_reply_to[1]) {
+                $value = '"' . $this->_reply_to[1] . '" ' . $value;
+            }
+            $headers[] = array("Reply-To", $value);
+        }
+        
         // To:, Cc:, Bcc:
         foreach ($this->_rcpt as $label => $rcpt) {
             foreach ($rcpt as $addr => $name) {




More information about the Solar-svn mailing list