Beispiel #1
0
 public function testAddAttachmentError()
 {
     $message = new Message();
     $this->setExpectedException("InvalidArgumentException", "'exe' is a blacklisted file extension.");
     $message->addAttachment("file.exe", "data");
 }
 public function testAddAttachmentFilenameTypeError()
 {
     $message = new Message();
     $this->setExpectedException("InvalidArgumentException", "Filename must be a string but was type integer");
     $message->addAttachment(7, "data");
 }
    public function DDE_Dep_Exctsubmit($shturl,$selectedunit,$customername,$checkarray,$selectedsheet,$customermail,$customeridname,$UserStamp){
        $test=array();
        $submit_array=array();$submitarray=array();
        $sub_exequery ="SELECT ETD .ETD_EMAIL_SUBJECT,ETD. ETD_EMAIL_BODY FROM  EMAIL_TEMPLATE_DETAILS ETD ,EMAIL_TEMPLATE ET WHERE (ET .ET_ID=ETD .ET_ID) AND ET_EMAIL_SCRIPT='DEPOSIT DEDUCTION'";
        $sub_rs = $this->db->query($sub_exequery);
        $subject_db=$sub_rs->row()->ETD_EMAIL_SUBJECT;
        $message_db=$sub_rs->row()->ETD_EMAIL_BODY;
        $rcontent = $customername." - ".$selectedunit;
        $subject =str_replace('[UNIT_NO - CUSTOMER_NAME]',$rcontent,$subject_db);
        $body =str_replace('[UNIT_NO-  CUSTOMER_NAME]',$rcontent,$message_db);
        $emailindex = strstr($customermail,'@',true);
        $eusername = strtoupper($emailindex);
        $body = str_replace('[MAILID_USERNAME]',$eusername,$body);
        $this->load->model('EILIB/Mdl_eilib_common_function');
        $EmailDisplayname=$this->Mdl_eilib_common_function->Get_MailDisplayName('DEPOSIT_DEDUCTION');
        $pdfheader=$selectedunit.'-'.$customername;
        for($k=0;$k<count($checkarray);$k++){
            $data5=array('DDE_flag'=>6,'shturl'=>$shturl,'selectedunit'=>$selectedunit,'customername'=>$customername,'checkarray'=>$checkarray[$k],
                'selectedsheet'=>$selectedsheet,'customeridname'=>$customeridname);
            $submit_array=$this->Mdl_eilib_common_function->Func_curl($data5);
            $submitarray[]=json_decode($submit_array,true);
        }
        try {
            $message = new Message();
            $message->setSender($EmailDisplayname.'<'.$UserStamp.'>');
            $message->addTo($customermail);
            $message->setSubject($subject);
            $message->setTextBody($body);
            for ($i = 0; $i < count($submitarray); $i++) {
                $test[]=$i+1;
                $data = implode(array_map("chr", $submitarray[$i][0]));
                $message->addAttachment($pdfheader . '.pdf', $data);
            }
            $message->send();
            $data5=array('DDE_flag'=>7);
            $response=$this->Mdl_eilib_common_function->Func_curl($data5);
            return  $submitarray;

        }
        catch (InvalidArgumentException $e) {
            return $e->getMessage();
        }
    }
Beispiel #4
0
$email_message = <<<EMAIL
guest1: {$submitted['guest1']}
guest2: {$submitted['guest2']}
coming: {$submitted['coming']}
meal_beef: {$submitted['meal_beef']}
meal_fish: {$submitted['meal_fish']}
meal_veggie: {$submitted['meal_veggie']}
dietary_restrictions: {$submitted['dietary_restrictions']}
brunch: {$submitted['brunch']}
song: {$submitted['song']}
message: {$submitted['message']}
EMAIL;
try {
    $message = new Message();
    $message->setSender('*****@*****.**');
    $message->addTo('*****@*****.**');
    $message->setSubject("RSVP to Beth & Ian's Wedding");
    $message->setTextBody($email_message);
    if (!empty($selfie)) {
        $message->addAttachment($selfie['name'], $selfie['data']);
    }
    $message->send();
    include 'views/thankyou.php';
} catch (Exception $e) {
    $error_message = <<<HTML
Couldn't send your message to Beth &amp; Ian.
The following error occurred:<br><br>
{$e}
HTML;
    include 'views/error.php';
}
    }
    $drop_query="DROP TABLE $temp_table_name ";
    $drop_query1="DROP TABLE $temp_table_name1 ";
    mysqli_query($con,$drop_query);
    mysqli_query($con,$drop_query1);
    $message=$message."</table></body></html>";
    $find='SSOMENS TIME SHEET REPORT-  '.$month_year;
    $messagepdf=str_replace($find,'',$message);
    $find1='HELLO '.$spladminname;
    $messagepdf=str_replace($find1,'<b>'.'SSOMENS TIME SHEET REPORT-  '.$month_year.'</b>',$messagepdf);
    $find2='SSOMENS TIME SHEET REPORT FOR THE FOLLOWING EMPLOYEE(S) - '.$month_year.':';
    $messagepdf=str_replace($find2,'',$messagepdf);
    ob_clean();
    $mpdf = new mPDF('utf-8',array(270,330));
    $mpdf->WriteHTML($messagepdf);
    $outputpdf=$mpdf->Output('SSOMENS TS REPORT ' .$month_year. '.pdf','s');
    ob_end_clean();
    $FILENAME='SSOMENS TS REPORT ' .$month_year. '.pdf';
    $message1 = new Message();
    $message1->setSender($admin);
    $message1->addTo($admin);
    $message1->addCc($sadmin);
    $message1->setSubject($mail_subject);
    $message1->setHtmlBody($message);
    $message1->addAttachment($FILENAME,$outputpdf);
    $message1->send();
}



Beispiel #6
0
 protected static function observe_send($file, $data, $att = [])
 {
     require_once __DIR__ . '/../models/userModel.php';
     $mail = self::observe_file2mail($file, $data);
     if (!isset($mail['from']) || !isset($mail['to']) || !isset($mail['subject'])) {
         return false;
     }
     $to = strtolower($mail['to']);
     if (strstr($to, ',')) {
         $to = @current(explode(',', $to));
     }
     $model = new userModel();
     $user = $model->find_one_by_email($to);
     if (isset($user['lang']) && $user['lang'] != 'en' && $user['lang']) {
         $file = str_replace('/en/', '/' . $user['lang'] . '/', $file);
         if (file_exists($file)) {
             $mail = self::observe_file2mail($file, $data);
         }
     }
     if (Bootstrap::$main->appengine) {
         $mail_options = ["sender" => Bootstrap::$main->getConfig('mail.sender'), "to" => $mail['to'], "subject" => $mail['subject'], "htmlBody" => $mail['msg'], "replyto" => $mail['from'], "header" => ['Resent-From' => $mail['from']]];
         try {
             $message = new Message($mail_options);
             foreach ($att as $a) {
                 foreach ($a as $k => $v) {
                     $message->addAttachment($k, $v);
                 }
             }
             return $message->send();
         } catch (Exception $e) {
             return false;
         }
     } else {
         $_att = '';
         foreach ($att as $a) {
             foreach ($a as $k => $v) {
                 $_att .= '<h3>' . $k . '</h3><pre>' . $v . '</pre>';
             }
         }
         return mail($mail['to'], $mail['subject'], $mail['msg'] . $_att, $mail['header']);
     }
 }
Beispiel #7
0
 public function testInvalidContentId()
 {
     $message = new Message();
     $this->setExpectedException("InvalidArgumentException", "Content-id must begin and end with angle brackets.");
     $message->addAttachment("foo.jpg", "image data", "invalid content id");
 }
 /**
  * Send email
  *
  * This is based on {@see wp_mail()} which is in turn based on PHP's
  * built-in mail() function. This is typically called from the overriden
  * version of {@see wp_mail()} below.
  *
  * @param string|array $to          Array or comma-separated list of email addresses to send message.
  * @param string       $subject     Email subject
  * @param string       $message     Message contents
  * @param string|array $headers     Optional. Additional headers.
  * @param string|array $attachments Optional. Files to attach.
  *
  * @return bool Whether the email contents were sent successfully.
  */
 function send_mail($to, $subject, $message, $headers = '', $attachments = array())
 {
     // Compact the input, apply the filters, and extract them back out
     extract(apply_filters('wp_mail', compact('to', 'subject', 'message', 'headers', 'attachments')));
     global $phpmailer;
     if (!is_object($phpmailer) || !is_a($phpmailer, 'Message')) {
         $phpmailer = new Message();
     }
     $cc = array();
     $bcc = array();
     // Headers
     if (empty($headers)) {
         $headers = array();
     } else {
         if (!is_array($headers)) {
             // Explode the headers out, so this function can take both
             // string headers and an array of headers.
             $tempheaders = explode("\n", str_replace("\r\n", "\n", $headers));
         } else {
             $tempheaders = $headers;
         }
         $headers = array();
         // If it's actually got contents
         if (!empty($tempheaders)) {
             // Iterate through the raw headers
             foreach ((array) $tempheaders as $header) {
                 if (false === strpos($header, ':')) {
                     if (false !== stripos($header, 'boundary=')) {
                         $parts = preg_split('/boundary=/i', trim($header));
                         $boundary = trim(str_replace(array("'", '"'), '', $parts[1]));
                     }
                     continue;
                 }
                 // Explode them out
                 list($name, $content) = explode(':', trim($header), 2);
                 // Cleanup crew
                 $name = trim($name);
                 $content = trim($content);
                 switch (strtolower($name)) {
                     // Mainly for legacy -- process a From: header if it's there
                     case 'from':
                         if (false !== strpos($content, '<')) {
                             // So... making my life hard again?
                             $from_name = substr($content, 0, strpos($content, '<') - 1);
                             $from_name = str_replace('"', '', $from_name);
                             $from_name = trim($from_name);
                             $from_email = substr($content, strpos($content, '<') + 1);
                             $from_email = str_replace('>', '', $from_email);
                             $from_email = trim($from_email);
                         } else {
                             $from_email = trim($content);
                         }
                         break;
                     case 'content-type':
                         if (false !== strpos($content, ';')) {
                             list($type, $charset) = explode(';', $content);
                             $content_type = trim($type);
                             if (false !== stripos($charset, 'charset=')) {
                                 $charset = trim(str_replace(array('charset=', '"'), '', $charset));
                             } elseif (false !== stripos($charset, 'boundary=')) {
                                 $boundary = trim(str_replace(array('BOUNDARY=', 'boundary=', '"'), '', $charset));
                                 $charset = '';
                             }
                         } else {
                             $content_type = trim($content);
                         }
                         break;
                     case 'cc':
                         $cc = array_merge((array) $cc, explode(',', $content));
                         break;
                     case 'bcc':
                         $bcc = array_merge((array) $bcc, explode(',', $content));
                         break;
                     default:
                         // Add it to our grand headers array
                         $headers[trim($name)] = trim($content);
                         break;
                 }
             }
         }
     }
     // Empty out the values that may be set
     $phpmailer->clearBcc();
     $phpmailer->clearCc();
     $phpmailer->clearReplyTo();
     $phpmailer->clearTo();
     // From email and name
     // If we don't have a name from the input headers
     if (!isset($from_name)) {
         $from_name = 'App Engine';
     }
     /* If we don't have an email from the input headers default to wordpress@$sitename
      * Some hosts will block outgoing mail from this address if it doesn't exist but
      * there's no easy alternative. Defaulting to admin_email might appear to be another
      * option but some hosts may refuse to relay mail from an unknown domain. See
      * http://trac.wordpress.org/ticket/5007.
      */
     if (!isset($from_email)) {
         $from_email = get_option('appengine_email', false);
         if (!$from_email) {
             $from_email = get_default_email();
         }
     }
     // Plugin authors can override the potentially troublesome default
     // TODO: Currently, App Engine doesn't support a from name. We should
     //       come back to this and fix it if/when it does
     //$phpmailer->setSender( apply_filters( 'wp_mail_from_name', $from_name ) . " <" . apply_filters( 'wp_mail_from', $from_email ) . ">");
     $phpmailer->setSender(apply_filters('wp_mail_from', $from_email));
     // Set destination addresses
     if (!is_array($to)) {
         $to = explode(',', $to);
     }
     foreach ((array) $to as $recipient) {
         try {
             // Break $recipient into name and address parts if in the format "Foo <*****@*****.**>"
             $recipient_name = '';
             if (preg_match('/(.*)<(.+)>/', $recipient, $matches)) {
                 if (count($matches) == 3) {
                     $recipient_name = $matches[1];
                     $recipient = $matches[2];
                 }
             }
             $phpmailer->addTo($recipient, $recipient_name);
         } catch (Exception $e) {
             syslog(LOG_DEBUG, 'Mail error: ' . $e->getMessage());
             continue;
         }
     }
     // Add any CC and BCC recipients
     $cc = array_filter($cc);
     $bcc = array_filter($bcc);
     if (!empty($cc)) {
         foreach ((array) $cc as $recipient) {
             try {
                 // Break $recipient into name and address parts if in the format "Foo <*****@*****.**>"
                 $recipient_name = '';
                 if (preg_match('/(.*)<(.+)>/', $recipient, $matches)) {
                     if (count($matches) == 3) {
                         $recipient_name = $matches[1];
                         $recipient = $matches[2];
                     }
                 }
                 $phpmailer->addCc($recipient, $recipient_name);
             } catch (Exception $e) {
                 syslog(LOG_DEBUG, 'Mail error: ' . $e->getMessage());
                 continue;
             }
         }
     }
     if (!empty($bcc)) {
         foreach ((array) $bcc as $recipient) {
             try {
                 // Break $recipient into name and address parts if in the format "Foo <*****@*****.**>"
                 $recipient_name = '';
                 if (preg_match('/(.*)<(.+)>/', $recipient, $matches)) {
                     if (count($matches) == 3) {
                         $recipient_name = $matches[1];
                         $recipient = $matches[2];
                     }
                 }
                 $phpmailer->addBcc($recipient, $recipient_name);
             } catch (Exception $e) {
                 syslog(LOG_DEBUG, 'Mail error: ' . $e->getMessage());
                 continue;
             }
         }
     }
     // Set Content-Type and charset
     // If we don't have a content-type from the input headers
     if (!isset($content_type)) {
         $content_type = 'text/plain';
     }
     $content_type = apply_filters('wp_mail_content_type', $content_type);
     // Set whether it's plaintext, depending on $content_type
     if ('text/html' == $content_type) {
         $phpmailer->setHtmlBody($message);
     } else {
         $phpmailer->setTextBody($message);
     }
     $phpmailer->setSubject($subject);
     // If we don't have a charset from the input headers
     if (!isset($charset)) {
         $charset = get_bloginfo('charset');
     }
     // Set the content-type and charset
     //$phpmailer->charsset = apply_filters( 'wp_mail_charset', $charset );
     // Set custom headers
     if (!empty($headers)) {
         if (isset($headers['MIME-Version'])) {
             unset($headers['MIME-Version']);
         }
         $phpmailer->addHeaderArray($headers);
         if (false !== stripos($content_type, 'multipart') && !empty($boundary)) {
             $phpmailer->addHeaderArray('Content-Type', sprintf("%s;\n\t boundary=\"%s\"", $content_type, $boundary));
         }
     }
     if (!empty($attachments)) {
         foreach ($attachments as $attachment) {
             try {
                 $name = basename($attachment);
                 $data = file_get_contents($attachment);
                 $phpmailer->addAttachment($name, $data);
             } catch (Exception $e) {
                 syslog(LOG_DEBUG, 'Mail error: ' . $e->getMessage());
                 continue;
             }
         }
     }
     // Send!
     $phpmailer->send();
     return true;
 }