Commit 9f2e3358cf3e6e2b97ccfd6ae89833f6dc57969c
1 parent
171b5561
reformatted, added the phpmailer class to the object, added a constructor that i…
…nitialises with the defaults, and a send method that only takes the necessary params as mandatory git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@813 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
150 additions
and
125 deletions
lib/email/Email.inc
| 1 | 1 | <?php |
| 2 | - | |
| 3 | - | |
| 4 | 2 | /** |
| 5 | -* | |
| 6 | -* Class Email | |
| 7 | -* | |
| 8 | -* Contains static functions concerned with sending emails | |
| 9 | -* | |
| 10 | -* @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa | |
| 11 | -* @date 19 January 2003 | |
| 12 | -* @package lib.email | |
| 13 | -*/ | |
| 3 | + * $Id$ | |
| 4 | + * | |
| 5 | + * Contains static functions concerned with sending emails | |
| 6 | + * | |
| 7 | + * @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa | |
| 8 | + * @version $Revision$ | |
| 9 | + * @package lib.email | |
| 10 | + */ | |
| 11 | +class Email { | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * The underlying emailer class | |
| 15 | + */ | |
| 16 | + var $oMailer; | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * Creates an email class, initialising the underlying mailer class | |
| 20 | + * with default system information | |
| 21 | + * | |
| 22 | + * @param string the sender's email address (optional) | |
| 23 | + * @param string the sender's name (optional) | |
| 24 | + */ | |
| 25 | + function Email($sFromEmail = "", $sFromName = "") { | |
| 26 | + global $default; | |
| 27 | + // create a new phpmailer object. | |
| 28 | + $this->oMailer = new phpmailer(); | |
| 29 | + $this->oMailer->isSMTP(); | |
| 30 | + $this->oMailer->Host = $default->system->get("emailServer"); | |
| 31 | + $this->oMailer->From = (strlen($sFromEmail) == 0) ? $default->system->get("emailFrom") : $sFromEmail; | |
| 32 | + $this->oMailer->FromName = (strlen($sFromName) == 0) ? $default->system->get("emailFromName") : $sFromName; | |
| 33 | + $this->oMailer->WordWrap = 100; | |
| 34 | + $this->oMailer->IsHTML(true); | |
| 35 | + } | |
| 36 | + | |
| 37 | + /** | |
| 38 | + * Sends an email to a specified recipient. | |
| 39 | + * | |
| 40 | + * @param string the sender's email address (optional) | |
| 41 | + * @param string the sender's name (optional) | |
| 42 | + * @param string the recipients email address | |
| 43 | + * @param string the subject of the email | |
| 44 | + * @param string the body of the email | |
| 45 | + * @return boolean true on email successfully sent, false otherwise and set $_SESSION["errorMessage"] | |
| 46 | + */ | |
| 47 | + function send($sToEmail, $sSubject, $sBody, $sFromEmail = "", $sFromName = "") { | |
| 48 | + global $default, $lang_err_email; | |
| 49 | + | |
| 50 | + // set defaults for optional params | |
| 51 | + $sFromEmail = ((strlen($sFromEmail) == 0) || ($sFromEmail == "")) ? $default->system->get("emailFrom") : $sFromEmail; | |
| 52 | + $sFromName = ((strlen($sFromName) == 0) || ($sFromName == "")) ? $default->system->get("emailFromName") : $sFromName; | |
| 53 | + | |
| 54 | + // set optional params | |
| 55 | + if ((strlen($sFromEmail) > 0) && ($sFromEmail != "")) { | |
| 56 | + $this->oMailer->From = $sFromEmail; | |
| 57 | + } | |
| 58 | + if ((strlen($sFromName) > 0) && ($sFromName != "")) { | |
| 59 | + $this->oMailer->FromName = $sFromName; | |
| 60 | + } | |
| 61 | + $this->oMailer->AddAddress($sToEmail); | |
| 62 | + $this->oMailer->Subject = stripslashes($sSubject); | |
| 63 | + $this->oMailer->Body = stripslashes($sBody); | |
| 64 | + | |
| 65 | + //send the email | |
| 66 | + if(!$this->oMailer->Send()) { | |
| 67 | + $_SESSION["errorMessage"] = $lang_err_email . " " . $this->oMailer->ErrorInfo; | |
| 68 | + return false; | |
| 69 | + } | |
| 70 | + return true; | |
| 71 | + } | |
| 72 | + | |
| 73 | + /** | |
| 74 | + * Sends an email containing a hyperlink to a specified recipient | |
| 75 | + * | |
| 76 | + * @param The sender's email address | |
| 77 | + * @param The sender's Name | |
| 78 | + * @param The recipients email address | |
| 79 | + * @param The subject heading for the email | |
| 80 | + * @param The Body of the email | |
| 81 | + * @param The hyperlink that should be sent | |
| 82 | + * | |
| 83 | + * @return boolean true on email successfully sent, false otherwise and set $_SESSION["errorMessage"] | |
| 84 | + * | |
| 85 | + * @todo check for special characters (including encoding the link correctly???) | |
| 86 | + * @todo need to test this on multiple mail clients, not just Outlook | |
| 87 | + */ | |
| 88 | + function sendHyperLink($FromEmail, $FromName, $ToEmail, $Subj, $EmailBody, $hyperlink) { | |
| 89 | + global $default; | |
| 90 | + | |
| 91 | + //get info from relevant fields. | |
| 92 | + $this->oMailer->From = $FromEmail; | |
| 93 | + $this->oMailer->FromName = $FromName; | |
| 94 | + $this->oMailer->AddAddress($ToEmail); | |
| 95 | + $this->oMailer->Subject = stripslashes($Subj); | |
| 96 | + $this->oMailer->Body = stripslashes($EmailBody) . ' ' . $hyperlink; | |
| 97 | + | |
| 98 | + //send the email | |
| 99 | + if(!$this->oMailer->Send()) { | |
| 100 | + $_SESSION["errorMessage"] = $lang_err_email . " " . $this->oMailer->ErrorInfo; | |
| 101 | + return false; | |
| 102 | + } | |
| 103 | + return true; | |
| 104 | + } | |
| 105 | + /** | |
| 106 | + * Sends an email ment for administration, | |
| 107 | + * | |
| 108 | + * @param The sender's email address | |
| 109 | + * @param The sender's Name | |
| 110 | + * @param The recipients email address | |
| 111 | + * @param The subject heading for the email | |
| 112 | + * @param The Body of the email | |
| 113 | + * @param The hyperlink that should be sent | |
| 114 | + * | |
| 115 | + * @return boolean true on email successfully sent, false otherwise and set $_SESSION["errorMessage"] | |
| 116 | + * | |
| 117 | + * @todo check for special characters (including encoding the link correctly???) | |
| 118 | + * @todo need to test this on multiple mail clients, not just Outlook | |
| 119 | + */ | |
| 120 | + function sendHelpEmail($FromEmail, $FromName, $ToEmail, $Subj, $EmailBody, $hyperlink) { | |
| 121 | + global $default; | |
| 122 | + | |
| 123 | + //get info from relevant fields. | |
| 124 | + $this->oMailer->From = $FromEmail; | |
| 125 | + $this->oMailer->FromName = $FromName; | |
| 126 | + $this->oMailer->AddAddress($ToEmail); | |
| 127 | + $this->oMailer->Subject = stripslashes($Subj) . ' ' . $hyperlink; //only difference from above | |
| 128 | + $this->oMailer->Body = stripslashes($EmailBody) . " <br>This bug can be found on this page: " . "<a href = ". $hyperlink .">". $hyperlink ."</a>"; | |
| 129 | + | |
| 130 | + //send the email | |
| 131 | + if(!$this->oMailer->Send()) { | |
| 132 | + $_SESSION["errorMessage"] = $lang_err_email . " " . $this->oMailer->ErrorInfo; | |
| 133 | + return false; | |
| 134 | + } | |
| 135 | + return true; | |
| 136 | + } | |
| 137 | + | |
| 138 | + function sendEmail($FromEmail, $FromName, $ToEmail, $Subj, $EmailBody) { | |
| 139 | + global $default; | |
| 14 | 140 | |
| 15 | -Class Email { | |
| 16 | - | |
| 141 | + //get info from relevant fields. | |
| 142 | + $this->oMailer->From = $FromEmail; | |
| 143 | + $this->oMailer->FromName = $FromName; | |
| 144 | + $this->oMailer->AddAddress($ToEmail); | |
| 145 | + $this->oMailer->Subject = stripslashes($Subj); | |
| 146 | + $this->oMailer->Body = stripslashes($EmailBody); | |
| 17 | 147 | |
| 18 | - /** | |
| 19 | - * Sends an email containing a hyperlink to a specified recipient | |
| 20 | - * | |
| 21 | - * @param The sender's email address | |
| 22 | - * @param The sender's Name | |
| 23 | - * @param The recipients email address | |
| 24 | - * @param The subject heading for the email | |
| 25 | - * @param The Body of the email | |
| 26 | - * @param The hyperlink that should be sent | |
| 27 | - * | |
| 28 | - * @return boolean true on email successfully sent, false otherwise and set $_SESSION["errorMessage"] | |
| 29 | - * | |
| 30 | - * @todo check for special characters (including encoding the link correctly???) | |
| 31 | - * @todo need to test this on multiple mail clients, not just Outlook | |
| 32 | - */ | |
| 33 | - function sendHyperLink($FromEmail, $FromName, $ToEmail, $Subj, $EmailBody, $hyperlink) | |
| 34 | - { | |
| 35 | - global $default; | |
| 36 | - | |
| 37 | - // create a new phpmailer object. | |
| 38 | - $emailHyperlink = new phpmailer(); | |
| 39 | - | |
| 40 | - //set up info | |
| 41 | - $emailHyperlink->isSMTP(); | |
| 42 | - $emailHyperlink->Host = $default->owl_email_server; // SMTP server | |
| 43 | - | |
| 44 | - //get info from relevant fields. | |
| 45 | - $emailHyperlink->From = $FromEmail; | |
| 46 | - $emailHyperlink->FromName = $FromName; | |
| 47 | - $emailHyperlink->AddAddress($ToEmail); | |
| 48 | - $emailHyperlink->Subject = stripslashes($Subj); | |
| 49 | - $emailHyperlink->Body = stripslashes($EmailBody) . ' ' . $hyperlink; | |
| 50 | - $emailHyperlink->WordWrap = 100; | |
| 51 | - $emailHyperlink->IsHTML(true); | |
| 52 | - | |
| 53 | - //send the email | |
| 54 | - if(!$emailHyperlink->Send()) { | |
| 55 | - $_SESSION["errorMessage"] = $lang_err_email . " " . $emailHyperlink->ErrorInfo; | |
| 56 | - return false; | |
| 57 | - } | |
| 58 | - return true; | |
| 59 | - } | |
| 60 | - /** | |
| 61 | - * Sends an email ment for administration, | |
| 62 | - * | |
| 63 | - * @param The sender's email address | |
| 64 | - * @param The sender's Name | |
| 65 | - * @param The recipients email address | |
| 66 | - * @param The subject heading for the email | |
| 67 | - * @param The Body of the email | |
| 68 | - * @param The hyperlink that should be sent | |
| 69 | - * | |
| 70 | - * @return boolean true on email successfully sent, false otherwise and set $_SESSION["errorMessage"] | |
| 71 | - * | |
| 72 | - * @todo check for special characters (including encoding the link correctly???) | |
| 73 | - * @todo need to test this on multiple mail clients, not just Outlook | |
| 74 | - */ | |
| 75 | - function sendHelpEmail($FromEmail, $FromName, $ToEmail, $Subj, $EmailBody, $hyperlink) | |
| 76 | - { | |
| 77 | - global $default; | |
| 78 | - | |
| 79 | - // create a new phpmailer object. | |
| 80 | - $emailHyperlink = new phpmailer(); | |
| 81 | - | |
| 82 | - //set up info | |
| 83 | - $emailHyperlink->isSMTP(); | |
| 84 | - $emailHyperlink->Host = $default->owl_email_server; // SMTP server | |
| 85 | - | |
| 86 | - //get info from relevant fields. | |
| 87 | - $emailHyperlink->From = $FromEmail; | |
| 88 | - $emailHyperlink->FromName = $FromName; | |
| 89 | - $emailHyperlink->AddAddress($ToEmail); | |
| 90 | - $emailHyperlink->Subject = stripslashes($Subj) . ' ' . $hyperlink; //only difference from above | |
| 91 | - $emailHyperlink->Body = stripslashes($EmailBody) . " <br>This bug can be found on this page: " . "<a href = ". $hyperlink .">". $hyperlink ."</a>"; | |
| 92 | - $emailHyperlink->WordWrap = 80; | |
| 93 | - $emailHyperlink->IsHTML(true); | |
| 94 | - | |
| 95 | - //send the email | |
| 96 | - if(!$emailHyperlink->Send()) { | |
| 97 | - $_SESSION["errorMessage"] = $lang_err_email . " " . $emailHyperlink->ErrorInfo; | |
| 98 | - return false; | |
| 99 | - } | |
| 100 | - return true; | |
| 101 | - } | |
| 102 | - | |
| 103 | - function sendEmail($FromEmail, $FromName, $ToEmail, $Subj, $EmailBody) | |
| 104 | - { | |
| 105 | - global $default; | |
| 106 | - | |
| 107 | - // create a new phpmailer object. | |
| 108 | - $emailHyperlink = new phpmailer(); | |
| 109 | - | |
| 110 | - //set up info | |
| 111 | - $emailHyperlink->isSMTP(); | |
| 112 | - $emailHyperlink->Host = $default->owl_email_server; // SMTP server | |
| 113 | - | |
| 114 | - //get info from relevant fields. | |
| 115 | - $emailHyperlink->From = $FromEmail; | |
| 116 | - $emailHyperlink->FromName = $FromName; | |
| 117 | - $emailHyperlink->AddAddress($ToEmail); | |
| 118 | - $emailHyperlink->Subject = stripslashes($Subj); | |
| 119 | - $emailHyperlink->Body = stripslashes($EmailBody); | |
| 120 | - $emailHyperlink->WordWrap = 100; | |
| 121 | - $emailHyperlink->IsHTML(true); | |
| 122 | - | |
| 123 | - //send the email | |
| 124 | - if(!$emailHyperlink->Send()) { | |
| 125 | - $_SESSION["errorMessage"] = $lang_err_email; | |
| 126 | - return false; | |
| 127 | - } | |
| 128 | - return true; | |
| 129 | - } | |
| 148 | + //send the email | |
| 149 | + if(!$this->oMailer->Send()) { | |
| 150 | + $_SESSION["errorMessage"] = $lang_err_email . " " . $this->oMailer->ErrorInfo; | |
| 151 | + return false; | |
| 152 | + } | |
| 153 | + return true; | |
| 154 | + } | |
| 130 | 155 | } |
| 131 | 156 | |
| 132 | 157 | ?> | ... | ... |