Commit b8cea73a92e923bf5182e87e76a747745d6f06f5

Authored by Michael Joseph
1 parent 54724069

added multiple email address support


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@1245 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/email/Email.inc
... ... @@ -27,9 +27,9 @@ class Email {
27 27 // create a new phpmailer object.
28 28 $this->oMailer = new phpmailer();
29 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;
  30 + $this->oMailer->Host = $default->emailServer;
  31 + $this->oMailer->From = (strlen($sFromEmail) == 0) ? $default->emailFrom : $sFromEmail;
  32 + $this->oMailer->FromName = (strlen($sFromName) == 0) ? $default->emailFromName : $sFromName;
33 33 $this->oMailer->WordWrap = 100;
34 34 $this->oMailer->IsHTML(true);
35 35 }
... ... @@ -37,11 +37,11 @@ class Email {
37 37 /**
38 38 * Sends an email to a specified recipient.
39 39 *
40   - * @param string the sender's email address (optional)
41   - * @param string the sender's name (optional)
42 40 * @param string the recipients email address
43 41 * @param string the subject of the email
44 42 * @param string the body of the email
  43 + * @param string the sender's email address (optional)
  44 + * @param string the sender's name (optional)
45 45 * @return boolean true on email successfully sent, false otherwise and set $_SESSION["errorMessage"]
46 46 */
47 47 function send($sToEmail, $sSubject, $sBody, $sFromEmail = "", $sFromName = "") {
... ... @@ -58,7 +58,19 @@ class Email {
58 58 if ((strlen($sFromName) > 0) && ($sFromName != "")) {
59 59 $this->oMailer->FromName = $sFromName;
60 60 }
61   - $this->oMailer->AddAddress($sToEmail);
  61 +
  62 + // if there are multiple addresses (; separated)
  63 + $aEmailAddresses = array();
  64 + if (strpos($sToEmail, ";") > 0) {
  65 + // explode them
  66 + $aEmailAddresses = explode(";", $sToEmail);
  67 + for ($i=0; $i<count($aEmailAddresses); $i++) {
  68 + $this->oMailer->AddAddress($aEmailAddresses[$i]);
  69 + $default->log->info("Email.inc adding " . $aEmailAddresses[$i]);
  70 + }
  71 + } else {
  72 + $this->oMailer->AddAddress($sToEmail);
  73 + }
62 74 $this->oMailer->Subject = stripslashes($sSubject);
63 75 $this->oMailer->Body = stripslashes($sBody);
64 76  
... ...
presentation/lookAndFeel/knowledgeTree/documentmanagement/emailBL.php
... ... @@ -39,11 +39,13 @@ if (checkSession()) {
39 39 } else {
40 40 $sMessage = "Your colleague, " . $oUser->getName() . ", wishes you to view the document entitled '" . $oDocument->getName() . "'.\n Click on the hyperlink below to view it";
41 41 }
42   - $sHyperLink = generateLink("/presentation/lookAndFeel/knowledgeTree/documentmanagement/viewBL.php", "fDocumentID=$fDocumentID", $oDocument->getName());
  42 + // add the link to the document to the mail
  43 + $sMessage .= ' ' . generateLink("/presentation/lookAndFeel/knowledgeTree/documentmanagement/viewBL.php", "fDocumentID=$fDocumentID", $oDocument->getName());
43 44  
44 45 //email the hyperlink
45   - $oEmail = new Email();
46   - $oEmail->sendHyperlink($default->owl_email_from, "MRC DMS", $fToEmail, "Document link", $sMessage, $sHyperLink);
  46 + $oEmail = new Email();
  47 + $oEmail->send($fToEmail, "Document link", $sMessage);
  48 +
47 49 //go back to the document view page
48 50 redirect("$default->rootUrl/control.php?action=viewDocument&fDocumentID=$fDocumentID");
49 51 } else {
... ... @@ -68,7 +70,7 @@ if (checkSession()) {
68 70  
69 71 $oPatternCustom = & new PatternCustom();
70 72 $oPatternCustom->setHtml(getDocumentEmailPage($oDocument));
71   - //$main->setErrorMessage("Please enter an email address of the form someone@somewhere.some postfix");
  73 + $main->setErrorMessage("Please enter an email address of the form someone@somewhere.some postfix");
72 74 $main->setCentralPayload($oPatternCustom);
73 75 $main->setFormAction($_SERVER["PHP_SELF"] . "?fDocumentID=$fDocumentID&fSendEmail=1");
74 76 $main->render();
... ... @@ -88,12 +90,18 @@ if (checkSession()) {
88 90  
89 91 /** use regex to validate the format of the email address */
90 92 function validateEmailAddress($sEmailAddress) {
91   - $bResult = ereg ("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $sEmailAddress );
92   - if ($bResult) {
93   - return TRUE;
  93 + $aEmailAddresses = array();
  94 + if (strpos($sEmailAddress, ";")) {
  95 + $aEmailAddresses = explode(";", $sEmailAddress);
94 96 } else {
95   - return FALSE;
  97 + $aEmailAddresses[] = $sEmailAddress;
96 98 }
  99 + $bToReturn = true;
  100 + for ($i=0; $i<count($aEmailAddresses); $i++) {
  101 + $bResult = ereg ("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $aEmailAddresses[$i] );
  102 + $bToReturn = $bToReturn && $bResult;
  103 + }
  104 + return $bToReturn;
97 105 }
98 106  
99 107 ?>
... ...
presentation/lookAndFeel/knowledgeTree/documentmanagement/emailUI.inc
... ... @@ -38,10 +38,10 @@ function getDocumentEmailPage($oDocument) {
38 38 global $default;
39 39 $sToRender = getDocumentPath($oDocument) . "\n<br>\n";
40 40 $sToRender .= "<table>\n";
41   - $sToRender .= "<th colspan=\"2\" align=\"left\">Email details</th>\n";
  41 + $sToRender .= "<th colspan=\"2\" align=\"left\">Email details</th>\n";
42 42 $sToRender .= "<tr><td>&nbsp</td><td>&nbsp</td></tr>\n";
43 43 $sToRender .= "<tr><td>Recipient name:</td><td><input type=\"text\" name=\"fToName\" /></td></tr>\n";
44   - $sToRender .= "<tr><td>Email address:</td><td><input type=\"text\" name=\"fToEmail\" /></td></tr>\n";
  44 + $sToRender .= "<tr><td>Email address:</td><td><input type=\"text\" name=\"fToEmail\" />(separate multiple addresses with a semicolon)</td></tr>\n";
45 45 $sToRender .= "<tr><td>&nbsp</td><td>&nbsp</td></tr>\n";
46 46 $sToRender .= "<tr><td><table><tr><td><input type=\"image\" src=\"$default->graphicsUrl/widgets/email.gif\" /></td><td><a href=\"$default->rootUrl/control.php?action=viewDocument&fDocumentID=" . $oDocument->getID() . "\"><img src=\"$default->graphicsUrl/widgets/cancel.gif\" border=\"0\"/></a></td></tr></table></td>\n";
47 47 $sToRender .= "</table>\n";
... ...