Advertisement
Guest User

change

a guest
Feb 14th, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.82 KB | None | 0 0
  1.     function send($subject="no title",$body="No message specified", $receiver='', $attachments = array() ) {
  2.         //TODO add an EM_Error global object, for this sort of error reporting. (@marcus like StatusNotice)
  3.         global $smtpsettings, $phpmailer, $cformsSettings;
  4.         $subject = html_entity_decode(wp_kses_data($subject)); //decode entities, but run kses first just in case users use placeholders containing html
  5.         if( is_array($receiver) ){
  6.             $receiver_emails = array();
  7.             foreach($receiver as $receiver_email){
  8.                 $receiver_emails[] = is_email($receiver_email);
  9.             }
  10.            
  11.             $emails_ok = !in_array(false, $receiver_emails);
  12.         }else{
  13.             $emails_ok = is_email($receiver);
  14.         }
  15.        
  16.         if( get_option('dbem_smtp_html') && get_option('dbem_smtp_html_br') ){
  17.             $body = nl2br($body);
  18.         }
  19.         if ( $emails_ok && get_option('dbem_rsvp_mail_send_method') == 'wp_mail' ){
  20.             $from = get_option('dbem_mail_sender_address');
  21.             $headers = get_option('dbem_mail_sender_name') ? 'From: '.get_option('dbem_mail_sender_name').' <'.$from.'>':'From: '.$from . "\r\n";
  22.             $headers .=  apply_filters('em_extend_email_headers', '', $subject);
  23.            
  24.             if( get_option('dbem_smtp_html') ){ //create filter to change content type to html in wp_mail
  25.                 add_filter('wp_mail_content_type',create_function('', 'return "text/html";'));
  26.             }
  27.            
  28.             $attachments =  apply_filters('em_email_attach_file', $attachments, $subject);
  29.             $send = wp_mail( $receiver, $subject, $body, $headers, $attachments );
  30.  
  31.             if(!$send){
  32.                 global $phpmailer;
  33.                 $this->errors[] = $phpmailer->ErrorInfo;
  34.             }
  35.             return $send;
  36.         }elseif( $emails_ok ){
  37.             $this->load_phpmailer();
  38.             $mail = new PHPMailer();
  39.             //$mail->SMTPDebug = true;
  40.             if( get_option('dbem_smtp_html') ){
  41.                 $mail->isHTML();
  42.             }
  43.             $mail->ClearAllRecipients();
  44.             $mail->ClearAddresses();
  45.             $mail->ClearAttachments();
  46.             $mail->CharSet = 'utf-8';
  47.             $mail->SetLanguage('en', dirname(__FILE__).'/');
  48.             $mail->PluginDir = dirname(__FILE__).'/phpmailer/';
  49.             $mail->Host = get_option('dbem_smtp_host');
  50.             $mail->port = get_option('dbem_rsvp_mail_port');
  51.             $mail->Username = get_option('dbem_smtp_username');  
  52.             $mail->Password = get_option('dbem_smtp_password');  
  53.             $mail->From = get_option('dbem_mail_sender_address');          
  54.             $mail->FromName = get_option('dbem_mail_sender_name'); // This is the from name in the email, you can put anything you like here
  55.             $mail->Body = $body;
  56.             $mail->Subject = $subject;
  57.             //add attachments
  58.             if( is_array($attachments) ){
  59.                 foreach($attachments as $attachment){
  60.                     $att = array('name'=> '', 'encoding' => 'base64', 'type' => 'application/octet-stream');
  61.                     if( is_array($attachment) ){
  62.                         $att = array_merge($att, $attachment);
  63.                     }else{
  64.                         $att['path'] = $attachment;
  65.                     }
  66.                     $mail->AddAttachment($att['path'], $att['name'], $att['encoding'], $att['type']);
  67.                 }
  68.             }          
  69.             do_action('em_mailer', $mail); //$mail will still be modified  
  70.             if(is_array($receiver)){
  71.                 foreach($receiver as $receiver_email){
  72.                     $mail->AddAddress($receiver_email);
  73.                 }
  74.             }else{
  75.                 $mail->AddAddress($receiver);  
  76.             }
  77.        
  78.             //Protocols
  79.             if( get_option('dbem_rsvp_mail_send_method') == 'qmail' ){      
  80.                 $mail->isQmail();
  81.             }elseif( get_option('dbem_rsvp_mail_send_method') == 'sendmail' ){      
  82.                 $mail->isSendmail();
  83.             }else {
  84.                 $mail->Mailer = get_option('dbem_rsvp_mail_send_method');
  85.             }                    
  86.             if(get_option('dbem_rsvp_mail_SMTPAuth') == '1'){
  87.                 $mail->SMTPAuth = TRUE;
  88.             }
  89.             $send = $mail->Send();
  90.             if(!$send){
  91.                 $this->errors[] = $mail->ErrorInfo;
  92.             }
  93.             do_action('em_mailer_sent', $mail, $send); //$mail can still be modified
  94.             return $send;
  95.         }else{
  96.             $this->errors[] = __('Please supply a valid email format.', 'events-manager');
  97.             return false;
  98.         }
  99.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement