Example #1
0
 /**
  * Send an email
  * 
  * @param string $from        Self explanatory
  * @param string $to          Self explanatory
  * @param string $subject     Self explanatory
  * @param string $text        Self explanatory
  * @param string $html        Self explanatory
  * @param array  $attachments Self explanatory
  * 
  * @return boolean
  */
 function send($from = "", $to = "", $subject = "", $text = "", $html = "", $attachments = array())
 {
     /*
             |--------------
             |  PHPMailer
             |--------------
     */
     if ($this->emailType == 'phpmailer') {
         require_once "PHPMailerAutoload.php";
         $email = new PHPMailer();
         // SMTP support
         if ($this->use_smtp) {
             $email->isSMTP();
             $email->Host = $this->smtp_host;
             if ($this->smtp_encryption != 'none') {
                 $email->SMTPSecure = $this->smtp_encryption;
             }
             $email->SMTPAuth = $this->use_smtp_auth;
             if ($this->use_smtp_auth) {
                 $email->Username = $this->smtp_username;
                 $email->Password = $this->smtp_password;
             }
         }
         // Meta
         $email->CharSet = 'UTF-8';
         // WSXELE-1067: Force UTF-8
         $email->Subject = $subject;
         $email->From = $from;
         $email->FromName = $from;
         $email->addAddress($to, $to);
         // Content
         $email->isHTML(true);
         $email->Body = $this->header . $this->styleHTML($html) . $this->footer;
         $email->AltBody = $text;
         // Attachments
         foreach ($attachments as $file) {
             if (isset($file['name']) && isset($file['content']) && isset($file['mime'])) {
                 $email->addStringAttachment($file['content'], $file['name'], 'base64', $file['mime'], 'attachment');
             }
         }
         if (!$email->send()) {
             $this->registerLog($email->ErrorInfo);
             return false;
         }
         return true;
     }
     /*
             |--------------
             |  WSX5 class
             |--------------
     */
     $email = new imEMail($from, $to, $subject, "utf-8");
     $email->setExpose($this->exposeWsx5);
     $email->setText($text);
     $email->setHTML($this->header . $this->styleHTML($html) . $this->footer);
     $email->setStandardType($this->emailType);
     foreach ($attachments as $a) {
         if (isset($a['name']) && isset($a['content']) && isset($a['mime'])) {
             $email->attachFile($a['name'], $a['content'], $a['mime']);
         }
     }
     if (!$email->send()) {
         $this->registerLog("Cannot send email with internal script");
         return false;
     }
     return true;
 }
Example #2
0
 /**
  * Send the email message sent by the Email Object form
  * @access public
  * @param form The form settings in an associative array (array)
  * @param form_data The posted text data in an associative array (array)
  * @param files_data The posted files data in an associative array (array)
  * @param user_only Set TRUE to send the email only to the customer who filled the form. This is used when the data is stored in a DB and a confirmation email is sent too (bool)
  */
 function sendFormEmail($form, $form_data, $files_data, $user_only = FALSE)
 {
     global $imSettings;
     if (!is_array($form)) {
         $settings = $imSettings['email_form'][$form_id];
     } else {
         $settings = $form;
     }
     //Form Data
     $txtData = "";
     $htmData = "";
     $csvHeader = "";
     $csvData = "";
     $keys = array_keys($form_data);
     foreach ($keys as $key) {
         if (is_array($form_data[$key])) {
             $txtData .= $key . ": " . implode(", ", $form_data[$key]) . "\r\n";
             $htmData .= "<tr valign=\"top\"><td width=\"25%\"><b>" . $key . ":</b></td><td>" . implode(", ", $form_data[$key]) . "</td></tr>";
             if ($settings['customer_csv'] || $settings['owner_csv']) {
                 $csvHeader .= $key . ";";
                 $csvData .= implode(", ", $form_data[$key]) . ";";
             }
         } else {
             $txtData .= $key . ": " . $form_data[$key] . "\r\n";
             // Is it an email?
             if (preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\\@([a-z0-9])' . '(([a-z0-9-])*([a-z0-9]))+' . '(\\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i', $form_data[$key])) {
                 $htmData .= "<tr valign=\"top\"><td width=\"25%\"><b>" . str_replace(array("\\'", '\\"'), array("'", '"'), $key) . ":</b></td><td><a href=\"mailto:" . $form_data[$key] . "\">" . $form_data[$key] . "</a></td></tr>";
             } else {
                 if (preg_match('/^http[s]?:\\/\\/[a-zA-Z0-9\\.\\-]{2,}\\.[a-zA-Z]{2,}/', $form_data[$key])) {
                     // Is it an URL?
                     $htmData .= "<tr valign=\"top\"><td width=\"25%\"><b>" . str_replace(array("\\'", '\\"'), array("'", '"'), $key) . ":</b></td><td><a href=\"" . $form_data[$key] . "\">" . $form_data[$key] . "</a></td></tr>";
                 } else {
                     $htmData .= "<tr valign=\"top\"><td width=\"25%\"><b>" . str_replace(array("\\'", '\\"'), array("'", '"'), $key) . ":</b></td><td>" . str_replace(array("\\'", '\\"'), array("'", '"'), $form_data[$key]) . "</td></tr>";
                 }
             }
             if ($settings['customer_csv'] || $settings['owner_csv']) {
                 $csvHeader .= str_replace(array("\\'", '\\"'), array("'", '"'), $key) . ";";
                 $csvData .= str_replace(array("\\'", '\\"'), array("'", '"'), $form_data[$key]) . ";";
             }
         }
     }
     // Template
     $htmHead = $imSettings['email']['header'];
     $htmFoot = $imSettings['email']['footer'];
     //Send email to owner
     if (!$user_only && isset($settings['owner_email_to']) && $settings['owner_email_to'] != "") {
         $txtMsg = $settings['owner_message'];
         $htmMsg = nl2br($settings['owner_message']);
         if (strpos($settings['owner_email_from'], "@") === FALSE) {
             $settings['owner_email_from'] = $form_data[$settings['owner_email_from']];
         }
         if ($settings['owner_email_from'] == "") {
             $settings['owner_email_from'] = $settings['owner_email_to'];
         }
         $oEmail = new imEMail($settings['owner_email_from'], $settings['owner_email_to'], $settings['owner_subject'], "utf-8");
         $oEmail->setText($txtMsg . "\n\n" . $txtData);
         $oEmail->setHTML($htmHead . $htmMsg . "<br><br><table border=0 width=\"100%\" style=\"" . $imSettings['email']['email_content_style'] . "\">" . $htmData . "</table>" . $htmFoot);
         if ($settings['owner_csv']) {
             $oEmail->attachFile("form_data.csv", $csvHeader . "\n" . $csvData, "text/csv");
         }
         if (count($files_data) > 0) {
             foreach ($files_data as $file) {
                 if (file_exists($file['tmp_name'])) {
                     $oEmail->attachFile($file['name'], file_get_contents($file['tmp_name']), $file['type']);
                 }
             }
         }
         $oEmail->send();
     }
     //Send email to user
     if (isset($settings['customer_email_to']) && $settings['customer_email_to'] != "") {
         $txtMsg = $settings['customer_message'];
         $htmMsg = nl2br($settings['customer_message']);
         if ($settings['customer_email_from'] == "") {
             $settings['customer_email_from'] = $settings['owner_email_to'];
         }
         $oEmail = new imEMail($settings['customer_email_from'], $form_data[$settings['customer_email_to']], $settings['customer_subject'], "utf-8");
         if ($settings['customer_csv']) {
             $oEmail->setHTML($htmHead . $htmMsg . "<br><br><table border=0 width=\"100%\" style=\"" . $imSettings['email']['email_content_style'] . "\">" . $htmData . "</table>" . $htmFoot);
             $oEmail->setText($txtMsg . "\n\n" . $txtData);
         } else {
             $oEmail->setText($txtMsg);
             $oEmail->setHTML($htmHead . $htmMsg . $htmFoot);
         }
         $oEmail->send();
     }
 }
 /**
  * Send an email
  * 
  * @param string $from        Self explanatory
  * @param string $to          Self explanatory
  * @param string $subject     Self explanatory
  * @param string $text        Self explanatory
  * @param string $html        Self explanatory
  * @param array  $attachments Self explanatory
  * 
  * @return boolean
  */
 function send($from = "", $to = "", $subject = "", $text = "", $html = "", $attachments = array())
 {
     $email = new imEMail($from, $to, $subject, "utf-8");
     $email->setText($text);
     $email->setHTML($this->header . $this->styleHTML($html) . $this->footer);
     $email->setStandardType($this->emailType);
     foreach ($attachments as $a) {
         if (isset($a['name']) && isset($a['content']) && isset($a['mime'])) {
             $email->attachFile($a['name'], $a['content'], $a['mime']);
         }
     }
     return $email->send();
 }
Example #4
0
 /**
  * Send an email
  * 
  * @param string $from        Self explanatory
  * @param string $to          Self explanatory
  * @param string $subject     Self explanatory
  * @param string $text        Self explanatory
  * @param string $html        Self explanatory
  * @param array  $attachments Self explanatory
  * 
  * @return boolean
  */
 function send($from = "", $to = "", $subject = "", $text = "", $html = "", $attachments = array())
 {
     /*
             |--------------
             |  PHPMailer
             |--------------
     */
     if ($this->emailType == 'phpmailer') {
         require_once "PHPMailerAutoload.php";
         $email = new PHPMailer();
         // SMTP support
         if ($this->use_smtp) {
             $email->isSMTP();
             $email->Host = $this->smtp_host;
             $email->Port = $this->smtp_port;
             if ($this->smtp_encryption != 'none') {
                 $email->SMTPSecure = $this->smtp_encryption;
             }
             $email->SMTPAuth = $this->use_smtp_auth;
             if ($this->use_smtp_auth) {
                 $email->Username = $this->smtp_username;
                 $email->Password = $this->smtp_password;
             }
         }
         // Meta
         $email->CharSet = 'UTF-8';
         // WSXELE-1067: Force UTF-8
         $email->Subject = $subject;
         $email->From = addressFromEmail($from);
         $email->FromName = nameFromEmail($from);
         // WSXELE-1120: Split the email addresses if necessary
         $to = str_replace(";", ",", $to);
         // Make sure it works for both "," and ";" separators
         foreach (explode(",", $to) as $addr) {
             // WSXELE-1157: Provide support for the format John Doe <*****@*****.**>
             $email->addAddress(addressFromEmail($addr), nameFromEmail($addr));
         }
         // Content
         $email->isHTML(true);
         $email->Body = $this->header . $this->styleHTML($html) . $this->footer;
         $email->AltBody = $text;
         // Attachments
         foreach ($attachments as $file) {
             if (isset($file['name']) && isset($file['content']) && isset($file['mime'])) {
                 $email->addStringAttachment($file['content'], $file['name'], 'base64', $file['mime'], 'attachment');
             }
         }
         if (!$email->send()) {
             $this->registerLog($email->ErrorInfo);
             return false;
         }
         return true;
     }
     /*
             |--------------
             |  WSX5 class
             |--------------
     */
     $email = new imEMail($from, $to, $subject, "utf-8");
     $email->setExpose($this->exposeWsx5);
     $email->setText($text);
     $email->setHTML($this->header . $this->styleHTML($html) . $this->footer);
     $email->setStandardType($this->emailType);
     foreach ($attachments as $a) {
         if (isset($a['name']) && isset($a['content']) && isset($a['mime'])) {
             $email->attachFile($a['name'], $a['content'], $a['mime']);
         }
     }
     if (!$email->send()) {
         $this->registerLog("Cannot send email with internal script");
         return false;
     }
     return true;
 }