Added feature #2797: Add return value to t3lib_htmlmail::send
authorOliver Hader <oliver.hader@typo3.org>
Mon, 14 Jan 2008 23:24:45 +0000 (23:24 +0000)
committerOliver Hader <oliver.hader@typo3.org>
Mon, 14 Jan 2008 23:24:45 +0000 (23:24 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@2887 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_htmlmail.php

index c5de4c9..8768c68 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2008-01-15  Oliver Hader  <oh@inpublica.de>
 
        * (feature) Added feature #7122: IRRE - Implement TYPO3AJAX handler for Inline Relational Record Editing
+       * (feature) Added feature #2797: Add return value to t3lib_htmlmail::send (thanks to Steffen Kamper)
 
 2008-01-14  Stanislas Rolland  <stanislas.rolland@fructifor.ca>
 
index dc89398..1e83e93 100755 (executable)
@@ -405,17 +405,19 @@ class t3lib_htmlmail {
        }
 
        /**
-        * [Describe function...]
+        * Assembles the message by headers and content and finally send it to the provided recipient.
         *
-        * @param       [type]          $recipient: ...
-        * @return      [type]          ...
+        * @param       string          $recipient: The recipient the message should be delivered to (if blank, $this->recipient will be used instead)
+        * @return      boolean         Returns whether the mail was sent (successfully accepted for delivery)
         */
-       function send($recipient)       {
-                       // This function sends the mail to one $recipient
-               if ($recipient) {$this->recipient = $recipient;}
+       function send($recipient='') {
+               if ($recipient) {
+                       $this->recipient = $recipient;
+               }
                $this->setHeaders();
                $this->setContent();
-               $this->sendTheMail();
+               $mailWasSent = $this->sendTheMail();
+               return $mailWasSent;
        }
 
 
@@ -687,10 +689,10 @@ class t3lib_htmlmail {
         *
         * With time this function should be made such that several ways of sending the mail is possible (local MTA, smtp other).
         *
-        * @return      [type]          ...
+        * @return      boolean         Returns whether the mail was sent (successfully accepted for delivery)
         */
-       function sendTheMail () {
-#debug(array($this->recipient,$this->subject,$this->message,$this->headers));
+       function sendTheMail() {
+               $mailWasSent = false;
                        // Sends the mail, requires the recipient, message and headers to be set.
                if (trim($this->recipient) && trim($this->message))     {       //  && trim($this->headers)
                        $returnPath = (strlen($this->returnPath)>0)?"-f".$this->returnPath:'';
@@ -700,30 +702,38 @@ class t3lib_htmlmail {
                        }
                                //If safe mode is on, the fifth parameter to mail is not allowed, so the fix wont work on unix with safe_mode=On
                        if(!ini_get('safe_mode') && $this->forceReturnPath) {
-                               mail($this->recipient,
-                                         $this->subject,
-                                         $this->message,
-                                         $this->headers,
-                                         $returnPath);
+                               $mailWasSent = mail(
+                                       $this->recipient,
+                                       $this->subject,
+                                       $this->message,
+                                       $this->headers,
+                                       $returnPath
+                               );
                        } else {
-                               mail($this->recipient,
-                                         $this->subject,
-                                         $this->message,
-                                         $this->headers);
+                               $mailWasSent = mail(
+                                       $this->recipient,
+                                       $this->subject,
+                                       $this->message,
+                                       $this->headers
+                               );
                        }
                                // Sending copy:
                        if ($this->recipient_copy)      {
                                if(!ini_get('safe_mode') && $this->forceReturnPath) {
-                                       mail(   $this->recipient_copy,
-                                                               $this->subject,
-                                                               $this->message,
-                                                               $this->headers,
-                                                               $returnPath);
+                                       $mailWasSent = mail(
+                                               $this->recipient_copy,
+                                               $this->subject,
+                                               $this->message,
+                                               $this->headers,
+                                               $returnPath
+                                       );
                                } else {
-                                       mail(   $this->recipient_copy,
-                                                               $this->subject,
-                                                               $this->message,
-                                                               $this->headers  );
+                                       $mailWasSent = mail(
+                                               $this->recipient_copy,
+                                               $this->subject,
+                                               $this->message,
+                                               $this->headers
+                                       );
                                }
                        }
                                // Auto response
@@ -731,23 +741,27 @@ class t3lib_htmlmail {
                                $theParts = explode('/',$this->auto_respond_msg,2);
                                $theParts[1] = str_replace("/",chr(10),$theParts[1]);
                                if(!ini_get('safe_mode') && $this->forceReturnPath) {
-                                       mail(   $this->from_email,
-                                                               $theParts[0],
-                                                               $theParts[1],
-                                                               "From: ".$this->recipient,
-                                                               $returnPath);
+                                       $mailWasSent = mail(
+                                               $this->from_email,
+                                               $theParts[0],
+                                               $theParts[1],
+                                               'From: '.$this->recipient,
+                                               $returnPath
+                                       );
                                } else {
-                                       mail(   $this->from_email,
-                                                               $theParts[0],
-                                                               $theParts[1],
-                                                               "From: ".$this->recipient);
+                                       $mailWasSent = mail(
+                                               $this->from_email,
+                                               $theParts[0],
+                                               $theParts[1],
+                                               'From: '.$this->recipient
+                                       );
                                }
                        }
                        if($this->returnPath) {
                                ini_restore(sendmail_from);
                        }
-                       return true;
-               } else {return false;}
+               }
+               return $mailWasSent;
        }
 
        /**