Example #1
0
 public function send()
 {
     Yii::import('application.extensions.smtpmail.PHPMailer');
     $mail = new PHPMailer();
     $mail->IsSMTP();
     $mail->Host = Yii::app()->user->getSetting('company.mail.server');
     $mail->SMTPAuth = Yii::app()->user->getSetting('company.mail.user') != '' ? true : false;
     $mail->SMTPSecure = Yii::app()->user->getSetting('company.mail.ssl') ? 'tls' : '';
     $mail->CharSet = 'utf-8';
     $mail->Port = Yii::app()->user->getSetting('company.mail.port');
     $mail->Username = Yii::app()->user->getSetting('company.mail.user');
     $mail->Password = Yii::app()->user->getSetting('company.mail.password');
     //$mail->SetFrom($this->from);
     //echo $this->files;
     if ($this->files != '') {
         $file = Files::model()->findByPk($this->files);
         if ($file != null) {
             //echo $file->getFullPath().";;".$file->name;
             $mail->AddAttachment($file->getFullFilePath(), $file->name);
         }
     }
     $mail->SetFrom(Yii::app()->user->settings['company.mail.address']);
     $mail->AddCC($this->cc);
     //.$this->cc
     $mail->AddBcc($this->bcc);
     $mail->Subject = $this->subject;
     $mail->MsgHTML($this->body);
     $mail->AddAddress($this->to, "");
     if (!$mail->Send()) {
         //echo "Mailer Error: " . $mail->ErrorInfo;
         throw new CHttpException(501, Yii::t('app', "Mailer Error: ") . $mail->ErrorInfo . $mail->Username);
     } else {
         $this->sent++;
         $this->save();
         Yii::app()->user->setFlash('success', Yii::t('app', 'Message sent!'));
         //echo "Message sent!";
     }
     //*/
     //Yii::app()->end();
 }
Example #2
0
 /**
  * Send mail, similar to PHP's mail
  *
  * A true return value does not automatically mean that the user received the
  * email successfully. It just only means that the method used was able to
  * process the request without any errors.
  *
  * Using the two 'wp_mail_from' and 'wp_mail_from_name' hooks allow from
  * creating a from address like 'Name <*****@*****.**>' when both are set. If
  * just 'wp_mail_from' is set, then just the email address will be used with no
  * name.
  *
  * The default content type is 'text/plain' which does not allow using HTML.
  * However, you can set the content type of the email by using the
  * 'wp_mail_content_type' filter.
  *
  * The default charset is based on the charset used on the blog. The charset can
  * be set using the 'wp_mail_charset' filter.
  *
  * @since 1.2.1
  *
  * @uses PHPMailer
  *
  * @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 wp_mail($to, $subject, $message, $headers = '', $attachments = array())
 {
     // Compact the input, apply the filters, and extract them back out
     /**
      * Filter the wp_mail() arguments.
      *
      * @since 2.2.0
      *
      * @param array $args A compacted array of wp_mail() arguments, including the "to" email,
      *                    subject, message, headers, and attachments values.
      */
     $atts = apply_filters('wp_mail', compact('to', 'subject', 'message', 'headers', 'attachments'));
     if (isset($atts['to'])) {
         $to = $atts['to'];
     }
     if (isset($atts['subject'])) {
         $subject = $atts['subject'];
     }
     if (isset($atts['message'])) {
         $message = $atts['message'];
     }
     if (isset($atts['headers'])) {
         $headers = $atts['headers'];
     }
     if (isset($atts['attachments'])) {
         $attachments = $atts['attachments'];
     }
     if (!is_array($attachments)) {
         $attachments = explode("\n", str_replace("\r\n", "\n", $attachments));
     }
     global $phpmailer;
     // (Re)create it, if it's gone missing
     if (!$phpmailer instanceof PHPMailer) {
         require_once ABSPATH . WPINC . '/class-phpmailer.php';
         require_once ABSPATH . WPINC . '/class-smtp.php';
         $phpmailer = new PHPMailer(true);
     }
     // 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();
         $cc = array();
         $bcc = array();
         // If it's actually got contents
         if (!empty($tempheaders)) {
             // Iterate through the raw headers
             foreach ((array) $tempheaders as $header) {
                 if (strpos($header, ':') === false) {
                     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':
                         $bracket_pos = strpos($content, '<');
                         if ($bracket_pos !== false) {
                             // Text before the bracketed email is the "From" name.
                             if ($bracket_pos > 0) {
                                 $from_name = substr($content, 0, $bracket_pos - 1);
                                 $from_name = str_replace('"', '', $from_name);
                                 $from_name = trim($from_name);
                             }
                             $from_email = substr($content, $bracket_pos + 1);
                             $from_email = str_replace('>', '', $from_email);
                             $from_email = trim($from_email);
                             // Avoid setting an empty $from_email.
                         } elseif ('' !== trim($content)) {
                             $from_email = trim($content);
                         }
                         break;
                     case 'content-type':
                         if (strpos($content, ';') !== false) {
                             list($type, $charset_content) = explode(';', $content);
                             $content_type = trim($type);
                             if (false !== stripos($charset_content, 'charset=')) {
                                 $charset = trim(str_replace(array('charset=', '"'), '', $charset_content));
                             } elseif (false !== stripos($charset_content, 'boundary=')) {
                                 $boundary = trim(str_replace(array('BOUNDARY=', 'boundary=', '"'), '', $charset_content));
                                 $charset = '';
                             }
                             // Avoid setting an empty $content_type.
                         } elseif ('' !== trim($content)) {
                             $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->ClearAllRecipients();
     $phpmailer->ClearAttachments();
     $phpmailer->ClearCustomHeaders();
     $phpmailer->ClearReplyTos();
     // From email and name
     // If we don't have a name from the input headers
     if (!isset($from_name)) {
         $from_name = 'WordPress';
     }
     /* 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
      * https://core.trac.wordpress.org/ticket/5007.
      */
     if (!isset($from_email)) {
         // Get the site domain and get rid of www.
         $sitename = strtolower($_SERVER['SERVER_NAME']);
         if (substr($sitename, 0, 4) == 'www.') {
             $sitename = substr($sitename, 4);
         }
         $from_email = 'wordpress@' . $sitename;
     }
     /**
      * Filter the email address to send from.
      *
      * @since 2.2.0
      *
      * @param string $from_email Email address to send from.
      */
     $phpmailer->From = apply_filters('wp_mail_from', $from_email);
     /**
      * Filter the name to associate with the "from" email address.
      *
      * @since 2.3.0
      *
      * @param string $from_name Name associated with the "from" email address.
      */
     $phpmailer->FromName = apply_filters('wp_mail_from_name', $from_name);
     // 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->AddAddress($recipient, $recipient_name);
         } catch (phpmailerException $e) {
             continue;
         }
     }
     // Set mail's subject and body
     $phpmailer->Subject = $subject;
     $phpmailer->Body = $message;
     // Add any CC and BCC recipients
     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 (phpmailerException $e) {
                 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 (phpmailerException $e) {
                 continue;
             }
         }
     }
     // Set to use PHP's mail()
     $phpmailer->IsMail();
     // 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';
     }
     /**
      * Filter the wp_mail() content type.
      *
      * @since 2.3.0
      *
      * @param string $content_type Default wp_mail() content type.
      */
     $content_type = apply_filters('wp_mail_content_type', $content_type);
     $phpmailer->ContentType = $content_type;
     // Set whether it's plaintext, depending on $content_type
     if ('text/html' == $content_type) {
         $phpmailer->IsHTML(true);
     }
     // If we don't have a charset from the input headers
     if (!isset($charset)) {
         $charset = get_bloginfo('charset');
     }
     // Set the content-type and charset
     /**
      * Filter the default wp_mail() charset.
      *
      * @since 2.3.0
      *
      * @param string $charset Default email charset.
      */
     $phpmailer->CharSet = apply_filters('wp_mail_charset', $charset);
     // Set custom headers
     if (!empty($headers)) {
         foreach ((array) $headers as $name => $content) {
             $phpmailer->AddCustomHeader(sprintf('%1$s: %2$s', $name, $content));
         }
         if (false !== stripos($content_type, 'multipart') && !empty($boundary)) {
             $phpmailer->AddCustomHeader(sprintf("Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary));
         }
     }
     if (!empty($attachments)) {
         foreach ($attachments as $attachment) {
             try {
                 $phpmailer->AddAttachment($attachment);
             } catch (phpmailerException $e) {
                 continue;
             }
         }
     }
     /**
      * Fires after PHPMailer is initialized.
      *
      * @since 2.2.0
      *
      * @param PHPMailer &$phpmailer The PHPMailer instance, passed by reference.
      */
     do_action_ref_array('phpmailer_init', array(&$phpmailer));
     // Send!
     try {
         return $phpmailer->Send();
     } catch (phpmailerException $e) {
         return false;
     }
 }
            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 (phpmailerException $e) {
            continue;
        }
    }
}
// Set to use PHP's mail()
$phpmailer->IsMail();
// 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);
$phpmailer->ContentType = $content_type;
// Set whether it's plaintext, depending on $content_type
Example #4
0
 /**
  * Send mail, similar to PHP's mail
  *
  * A true return value does not automatically mean that the user received the
  * email successfully. It just only means that the method used was able to
  * process the request without any errors.
  *
  * Using the two 'wp_mail_from' and 'wp_mail_from_name' hooks allow from
  * creating a from address like 'Name <*****@*****.**>' when both are set. If
  * just 'wp_mail_from' is set, then just the email address will be used with no
  * name.
  *
  * The default content type is 'text/plain' which does not allow using HTML.
  * However, you can set the content type of the email by using the
  * 'wp_mail_content_type' filter.
  *
  * The default charset is based on the charset used on the blog. The charset can
  * be set using the 'wp_mail_charset' filter.
  *
  * @since 1.2.1
  * @uses apply_filters() Calls 'wp_mail' hook on an array of all of the parameters.
  * @uses apply_filters() Calls 'wp_mail_from' hook to get the from email address.
  * @uses apply_filters() Calls 'wp_mail_from_name' hook to get the from address name.
  * @uses apply_filters() Calls 'wp_mail_content_type' hook to get the email content type.
  * @uses apply_filters() Calls 'wp_mail_charset' hook to get the email charset
  * @uses do_action_ref_array() Calls 'phpmailer_init' hook on the reference to
  *		phpmailer object.
  * @uses PHPMailer
  * @
  *
  * @param string $to Email address to send message
  * @param string $subject Email subject
  * @param string $message Message contents
  * @param string|array $headers Optional. Additional headers.
  * @return bool Whether the email contents were sent successfully.
  */
 function wp_mail($to, $subject, $message, $headers = '')
 {
     // Compact the input, apply the filters, and extract them back out
     extract(apply_filters('wp_mail', compact('to', 'subject', 'message', 'headers')));
     global $phpmailer;
     // (Re)create it, if it's gone missing
     if (!is_object($phpmailer) || !is_a($phpmailer, 'PHPMailer')) {
         require_once ABSPATH . WPINC . '/class-phpmailer.php';
         require_once ABSPATH . WPINC . '/class-smtp.php';
         $phpmailer = new PHPMailer();
     }
     // Headers
     if (empty($headers)) {
         $headers = array();
     } elseif (!is_array($headers)) {
         // Explode the headers out, so this function can take both
         // string headers and an array of headers.
         $tempheaders = (array) explode("\n", $headers);
         $headers = array();
         // If it's actually got contents
         if (!empty($tempheaders)) {
             // Iterate through the raw headers
             foreach ($tempheaders as $header) {
                 if (strpos($header, ':') === false) {
                     continue;
                 }
                 // Explode them out
                 list($name, $content) = explode(':', trim($header), 2);
                 // Cleanup crew
                 $name = trim($name);
                 $content = trim($content);
                 // Mainly for legacy -- process a From: header if it's there
                 if ('from' == strtolower($name)) {
                     if (strpos($content, '<') !== false) {
                         // 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_name = trim($content);
                     }
                 } elseif ('content-type' == strtolower($name)) {
                     if (strpos($content, ';') !== false) {
                         list($type, $charset) = explode(';', $content);
                         $content_type = trim($type);
                         $charset = trim(str_replace(array('charset=', '"'), '', $charset));
                     } else {
                         $content_type = trim($content);
                     }
                 } elseif ('cc' == strtolower($name)) {
                     $cc = explode(",", $content);
                 } elseif ('bcc' == strtolower($name)) {
                     $bcc = explode(",", $content);
                 } else {
                     // Add it to our grand headers array
                     $headers[trim($name)] = trim($content);
                 }
             }
         }
     }
     // Empty out the values that may be set
     $phpmailer->ClearAddresses();
     $phpmailer->ClearAllRecipients();
     $phpmailer->ClearAttachments();
     $phpmailer->ClearBCCs();
     $phpmailer->ClearCCs();
     $phpmailer->ClearCustomHeaders();
     $phpmailer->ClearReplyTos();
     // From email and name
     // If we don't have a name from the input headers
     if (!isset($from_name)) {
         $from_name = 'WordPress';
     }
     // If we don't have an email from the input headers
     if (!isset($from_email)) {
         // Get the site domain and get rid of www.
         $sitename = strtolower($_SERVER['SERVER_NAME']);
         if (substr($sitename, 0, 4) == 'www.') {
             $sitename = substr($sitename, 4);
         }
         $from_email = 'wordpress@' . $sitename;
     }
     // Set the from name and email
     $phpmailer->From = apply_filters('wp_mail_from', $from_email);
     $phpmailer->FromName = apply_filters('wp_mail_from_name', $from_name);
     // Set destination address
     $phpmailer->AddAddress($to);
     // Set mail's subject and body
     $phpmailer->Subject = $subject;
     $phpmailer->Body = $message;
     // Add any CC and BCC recipients
     if (!empty($cc)) {
         foreach ($cc as $recipient) {
             $phpmailer->AddCc(trim($recipient));
         }
     }
     if (!empty($bcc)) {
         foreach ($bcc as $recipient) {
             $phpmailer->AddBcc(trim($recipient));
         }
     }
     // Set to use PHP's mail()
     $phpmailer->IsMail();
     // 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 or not, depending on $content_type
     if ($content_type == 'text/html') {
         $phpmailer->IsHTML(true);
     } else {
         $phpmailer->IsHTML(false);
     }
     // 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->CharSet = apply_filters('wp_mail_charset', $charset);
     // Set custom headers
     if (!empty($headers)) {
         foreach ($headers as $name => $content) {
             $phpmailer->AddCustomHeader(sprintf('%1$s: %2$s', $name, $content));
         }
     }
     do_action_ref_array('phpmailer_init', array(&$phpmailer));
     // Send!
     $result = @$phpmailer->Send();
     return $result;
 }
 /**
  * Send mail, similar to PHP's mail
  *
  * A true return value does not automatically mean that the user received the
  * email successfully. It just only means that the method used was able to
  * process the request without any errors.
  *
  * Using the two 'bb_mail_from' and 'bb_mail_from_name' hooks allow from
  * creating a from address like 'Name <*****@*****.**>' when both are set. If
  * just 'bb_mail_from' is set, then just the email address will be used with no
  * name.
  *
  * The default content type is 'text/plain' which does not allow using HTML.
  * However, you can set the content type of the email by using the
  * 'bb_mail_content_type' filter.
  *
  * The default charset is based on the charset used on the blog. The charset can
  * be set using the 'bb_mail_charset' filter.
  *
  * @uses apply_filters() Calls 'bb_mail' hook on an array of all of the parameters.
  * @uses apply_filters() Calls 'bb_mail_from' hook to get the from email address.
  * @uses apply_filters() Calls 'bb_mail_from_name' hook to get the from address name.
  * @uses apply_filters() Calls 'bb_mail_content_type' hook to get the email content type.
  * @uses apply_filters() Calls 'bb_mail_charset' hook to get the email charset
  * @uses do_action_ref_array() Calls 'bb_phpmailer_init' hook on the reference to
  *		phpmailer object.
  * @uses PHPMailer
  *
  * @param string $to Email address 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 bb_mail($to, $subject, $message, $headers = '', $attachments = array())
 {
     // Compact the input, apply the filters, and extract them back out
     extract(apply_filters('bb_mail', compact('to', 'subject', 'message', 'headers', 'attachments')));
     if (!is_array($attachments)) {
         $attachments = explode("\n", $attachments);
     }
     global $bb_phpmailer;
     // (Re)create it, if it's gone missing
     if (!is_object($bb_phpmailer) || !is_a($bb_phpmailer, 'PHPMailer')) {
         require_once BACKPRESS_PATH . 'class.mailer.php';
         require_once BACKPRESS_PATH . 'class.mailer-smtp.php';
         $bb_phpmailer = new PHPMailer();
     }
     // 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 = (array) explode("\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 (strpos($header, ':') === false) {
                     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);
                 // Mainly for legacy -- process a From: header if it's there
                 if ('from' == strtolower($name)) {
                     if (strpos($content, '<') !== false) {
                         // 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);
                     }
                 } elseif ('content-type' == strtolower($name)) {
                     if (strpos($content, ';') !== false) {
                         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);
                     }
                 } elseif ('cc' == strtolower($name)) {
                     $cc = explode(",", $content);
                 } elseif ('bcc' == strtolower($name)) {
                     $bcc = explode(",", $content);
                 } else {
                     // Add it to our grand headers array
                     $headers[trim($name)] = trim($content);
                 }
             }
         }
     }
     // Empty out the values that may be set
     $bb_phpmailer->ClearAddresses();
     $bb_phpmailer->ClearAllRecipients();
     $bb_phpmailer->ClearAttachments();
     $bb_phpmailer->ClearBCCs();
     $bb_phpmailer->ClearCCs();
     $bb_phpmailer->ClearCustomHeaders();
     $bb_phpmailer->ClearReplyTos();
     // From email and name
     // If we don't have a name from the input headers
     if (!isset($from_name)) {
         $from_name = bb_get_option('name');
     }
     // If we don't have an email from the input headers
     if (!isset($from_email)) {
         $from_email = bb_get_option('from_email');
     }
     // If there is still no email address
     if (!$from_email) {
         // Get the site domain and get rid of www.
         $sitename = strtolower($_SERVER['SERVER_NAME']);
         if (substr($sitename, 0, 4) == 'www.') {
             $sitename = substr($sitename, 4);
         }
         $from_email = 'bbpress@' . $sitename;
     }
     // Plugin authors can override the potentially troublesome default
     $bb_phpmailer->From = apply_filters('bb_mail_from', $from_email);
     $bb_phpmailer->FromName = apply_filters('bb_mail_from_name', $from_name);
     // Set destination address
     $bb_phpmailer->AddAddress($to);
     // Set mail's subject and body
     $bb_phpmailer->Subject = $subject;
     $bb_phpmailer->Body = $message;
     // Add any CC and BCC recipients
     if (!empty($cc)) {
         foreach ((array) $cc as $recipient) {
             $bb_phpmailer->AddCc(trim($recipient));
         }
     }
     if (!empty($bcc)) {
         foreach ((array) $bcc as $recipient) {
             $bb_phpmailer->AddBcc(trim($recipient));
         }
     }
     // Set to use PHP's mail()
     $bb_phpmailer->IsMail();
     // 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('bb_mail_content_type', $content_type);
     $bb_phpmailer->ContentType = $content_type;
     // Set whether it's plaintext or not, depending on $content_type
     if ($content_type == 'text/html') {
         $bb_phpmailer->IsHTML(true);
     }
     // If we don't have a charset from the input headers
     if (!isset($charset)) {
         $charset = bb_get_option('charset');
     }
     // Set the content-type and charset
     $bb_phpmailer->CharSet = apply_filters('bb_mail_charset', $charset);
     // Set custom headers
     if (!empty($headers)) {
         foreach ((array) $headers as $name => $content) {
             $bb_phpmailer->AddCustomHeader(sprintf('%1$s: %2$s', $name, $content));
         }
         if (false !== stripos($content_type, 'multipart') && !empty($boundary)) {
             $bb_phpmailer->AddCustomHeader(sprintf("Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary));
         }
     }
     if (!empty($attachments)) {
         foreach ($attachments as $attachment) {
             $bb_phpmailer->AddAttachment($attachment);
         }
     }
     do_action_ref_array('bb_phpmailer_init', array(&$bb_phpmailer));
     // Send!
     $result = @$bb_phpmailer->Send();
     return $result;
 }
Example #6
0
/**
 * Function to mail the content
 * @param string $content
 * @param string $subject
 * @param string $email           (from email)
 * @param string $realname        (from name)
 * @param string/array $recipient (to)
 * @return void
 */
function mail_it($content, $subject, $email, $realname, $recipient, $inbound = true)
{
    global $attachment_chunk, $attachment_name, $attachment_type, $attachment_temp;
    global $local_chunk, $local_name, $local_type, $local_temp;
    global $bcc, $cc;
    global $PHPMailerLocation, $PHPMailerLiteLocation;
    global $fixedFromEmail, $fixedFromName, $text_only, $htmlCharset;
    global $addToCSV;
    $valSent = false;
    if ($realname) {
        $sendTo = $realname . "<" . $email . ">";
    } else {
        $sendTo = $email;
    }
    $ob = "----=_OuterBoundary_000";
    $ib = "----=_InnerBoundery_001";
    $mail_headers = "MIME-Version: 1.0\r\n";
    if ($fixedFromEmail != '') {
        $mail_headers .= "From: " . $fixedFromEmail . "\n";
    } else {
        $mail_headers .= "From: " . $sendTo . "\n";
    }
    $mail_headers .= "To: " . $recipient . "\n";
    $mail_headers .= "Reply-To: " . $sendTo . "\n";
    if ($cc) {
        $mail_headers .= "Cc: " . $cc . "\n";
    }
    if ($bcc) {
        $mail_headers .= "Bcc: " . $bcc . "\n";
    }
    $mail_headers .= "X-Priority: 1\n";
    $mail_headers .= "X-Mailer: PHPMailer-FE v" . VERSION . " (software by worxware.com)\n";
    $mail_headers .= "Content-Type: multipart/mixed;\n\tboundary=\"" . $ob . "\"\n";
    $mail_message = "This is a multi-part message in MIME format.\n";
    $mail_message .= "\n--" . $ob . "\n";
    $mail_message .= "Content-Type: multipart/alternative;\n\tboundary=\"" . $ib . "\"\n\n";
    $mail_message .= "\n--" . $ib . "\n";
    $mail_message .= "Content-Type: text/plain;\n\tcharset=\"" . $htmlCharset . "\"\n";
    $mail_message .= "Content-Transfer-Encoding: quoted-printable\n\n";
    $mail_message .= $content["text"] . "\n\n";
    $mail_message .= "\n--" . $ib . "--\n";
    if ($attachment_name && $inbound) {
        reset($attachment_name);
        reset($attachment_temp);
        //loop through the arrays to get the attached file names and attach each one.
        while ((list($key1, $val1) = each($attachment_name)) && (list($key2, $val2) = each($attachment_temp)) && (list($key3, $val3) = each($attachment_type)) && (list($key4, $val4) = each($attachment_chunk))) {
            $mail_message .= "\n--" . $ob . "\n";
            $mail_message .= "Content-Type: {$val3};\n\tname=\"" . $val1 . "\"\n";
            $mail_message .= "Content-Transfer-Encoding: base64\n";
            $mail_message .= "Content-Disposition: attachment;\n\tfilename=\"" . $val1 . "\"\n\n";
            $mail_message .= $val4;
            $mail_message .= "\n\n";
        }
    } else {
        if ($local_name && $inbound === false) {
            $mail_message .= "\n--" . $ob . "\n";
            $mail_message .= "Content-Type: {$local_type};\n\tname=\"" . $local_name . "\"\n";
            $mail_message .= "Content-Transfer-Encoding: base64\n";
            $mail_message .= "Content-Disposition: attachment;\n\tfilename=\"" . $local_name . "\"\n\n";
            $mail_message .= $local_chunk;
            $mail_message .= "\n\n";
        }
    }
    $mail_message .= "\n--" . $ob . "--\n";
    if ((class_exists('PHPMailerLite') || class_exists('PHPMailer') || file_exists($PHPMailerLocation) || file_exists($PHPMailerLiteLocation)) && $_POST['text_only'] !== true) {
        if (!class_exists('PHPMailerLite') && file_exists($PHPMailerLiteLocation)) {
            require_once $PHPMailerLiteLocation;
            $mail = new PHPMailerLite();
        } elseif (!class_exists('PHPMailer') && file_exists($PHPMailerLocation)) {
            require_once $PHPMailerLocation;
            $mail = new PHPMailer();
        }
        if (isset($_POST['Mailer']) && strtolower(trim($_POST['Mailer'])) == "smtp") {
            $mail->IsSMTP();
            if (isset($_POST['Host']) && trim($_POST['Host']) != "") {
                $mail->Host = trim($_POST['Host']);
            }
            if (isset($_POST['Port']) && trim($_POST['Port']) != "") {
                $mail->Port = trim($_POST['Port']);
            }
            if (isset($_POST['SMTPAuth']) && ($_POST['SMTPAuth'] === true || $_POST['SMTPAuth'] === false)) {
                $mail->SMTPAuth = $_POST['SMTPAuth'];
            }
            if (isset($_POST['Username']) && trim($_POST['Username']) != "") {
                $mail->Username = trim($_POST['Username']);
            }
            if (isset($_POST['Username']) && trim($_POST['Username']) != "") {
                $mail->Password = trim($_POST['Password']);
            }
            if (isset($_POST['Timeout']) && trim($_POST['Timeout']) != "") {
                $mail->Timeout = trim($_POST['Timeout']);
            }
        } elseif (isset($_POST['Mailer']) && strtolower(trim($_POST['Mailer'])) == "sendmail") {
            $mail->IsSendmail();
        } elseif (isset($_POST['Mailer']) && strtolower(trim($_POST['Mailer'])) == "qmail") {
            $mail->IsQmail();
        }
        if (isset($_POST['fixedFromEmail'])) {
            if (isset($_POST['fixedFromName']) && trim($_POST['fixedFromName']) == '') {
                $_POST['fixedFromName'] = $_POST['fixedFromEmail'];
            }
            if (stristr($mail->Version, '5.1')) {
                $mail->SetFrom($_POST['fixedFromEmail'], $_POST['fixedFromName']);
            } elseif (stristr($mail->Version, '5')) {
                $mail->SetFrom($_POST['fixedFromEmail'], $_POST['fixedFromName']);
                $mail->AddReplyTo($_POST['fixedFromEmail'], $_POST['fixedFromName']);
            } else {
                $mail->SetFrom($_POST['fixedFromEmail'], $_POST['fixedFromName']);
            }
        } else {
            if (!isset($realname) && trim($realname) == '') {
                $realname = $email;
            }
            if (stristr($mail->Version, '5.1')) {
                $mail->SetFrom($email, $realname);
            } elseif ($mail->Version >= 5) {
                $mail->SetFrom($email, $realname);
                $mail->AddReplyTo($email, $realname);
            } else {
                $mail->From = $email;
                $mail->FromName = $realname;
            }
        }
        $mail->Subject = $subject;
        $mail->AddAddress($recipient);
        if ($bcc) {
            if (strpos($bcc, ",") || strpos($bcc, ";")) {
                $bcc_in = explode(',', $bcc);
                foreach ($bcc_in as $key => $value) {
                    $mail->AddBcc($value);
                }
            } else {
                $mail->AddBcc($bcc);
            }
        }
        if ($cc) {
            if (strpos($cc, ",") || strpos($cc, ";")) {
                $cc_in = explode(',', $cc);
                foreach ($cc_in as $key => $value) {
                    $mail->AddCc($value);
                }
            } else {
                $mail->AddCc($cc);
            }
        }
        $mail->MsgHTML($content["html"]);
        $mail->AltBody = _html2txt($content['html']);
        if ($attachment_name && $inbound) {
            //Add attachment function is in phpmailer
            //reset the arrays to the top
            reset($attachment_name);
            reset($attachment_temp);
            //loop through the arrays to get the attached file names and attach each one.
            while ((list($key1, $val1) = each($attachment_name)) && (list($key2, $val2) = each($attachment_temp))) {
                $atchmnt = file_get_contents($val2);
                $mail->AddStringAttachment($atchmnt, $val1);
            }
        } else {
            if ($local_name && $inbound === false) {
                $mail->AddAttachment($local_temp, $local_name);
            }
        }
        if ($mail->Send()) {
            echo '<script type="text/javascript">document.getElementById("feprocessing").src="_src/complete.gif";</script>';
            $valSent = true;
        }
    } else {
        if (@mail($recipient, $subject, $mail_message, $mail_headers)) {
            echo '<script type="text/javascript">document.getElementById("feprocessing").src="_src/complete.gif";</script>';
            $valSent = true;
        }
    }
    if ($addToCSV) {
        $writeVal = _writeLine($subject, $content['csv']);
    }
    if ($valSent) {
        return true;
    }
}
Example #7
0
 /**
  * Send mail, similar to PHP's mail
  *
  * A true return value does not automatically mean that the user received the
  * email successfully. It just only means that the method used was able to
  * process the request without any errors.
  *
  * Using the two 'wp_mail_from' and 'wp_mail_from_name' hooks allow from
  * creating a from address like 'Name <*****@*****.**>' when both are set. If
  * just 'wp_mail_from' is set, then just the email address will be used with no
  * name.
  *
  * The default content type is 'text/plain' which does not allow using HTML.
  * However, you can set the content type of the email by using the
  * 'wp_mail_content_type' filter.
  *
  * The default charset is based on the charset used on the blog. The charset can
  * be set using the 'wp_mail_charset' filter.
  *
  * @since 1.2.1
  * @uses apply_filters() Calls 'wp_mail' hook on an array of all of the parameters.
  * @uses apply_filters() Calls 'wp_mail_from' hook to get the from email address.
  * @uses apply_filters() Calls 'wp_mail_from_name' hook to get the from address name.
  * @uses apply_filters() Calls 'wp_mail_content_type' hook to get the email content type.
  * @uses apply_filters() Calls 'wp_mail_charset' hook to get the email charset
  * @uses do_action_ref_array() Calls 'phpmailer_init' hook on the reference to
  *		phpmailer object.
  * @uses PHPMailer
  * @
  *
  * @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 wp_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')));
     if (!is_array($attachments)) {
         $attachments = explode("\n", str_replace("\r\n", "\n", $attachments));
     }
     global $phpmailer;
     // (Re)create it, if it's gone missing
     if (!is_object($phpmailer) || !is_a($phpmailer, 'PHPMailer')) {
         require_once BACKPRESS_PATH . '/class.mailer.php';
         require_once BACKPRESS_PATH . '/class.mailer-smtp.php';
         $phpmailer = new PHPMailer();
     }
     // 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 (strpos($header, ':') === false) {
                     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 (strpos($content, '<') !== false) {
                             // 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 (strpos($content, ';') !== false) {
                             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;
                     case 'message-id':
                         $message_id = trim($content);
                     default:
                         // Add it to our grand headers array
                         $headers[trim($name)] = trim($content);
                         break;
                 }
             }
         }
     }
     // Empty out the values that may be set
     $phpmailer->ClearAddresses();
     $phpmailer->ClearAllRecipients();
     $phpmailer->ClearAttachments();
     $phpmailer->ClearBCCs();
     $phpmailer->ClearCCs();
     $phpmailer->ClearCustomHeaders();
     $phpmailer->ClearReplyTos();
     // From email and name
     // If we don't have a name from the input headers
     if (!isset($from_name)) {
         $from_name = 'WordPress';
     }
     /* 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)) {
         // Get the site domain and get rid of www.
         $sitename = strtolower($_SERVER['SERVER_NAME']);
         if (substr($sitename, 0, 4) == 'www.') {
             $sitename = substr($sitename, 4);
         }
         $from_email = 'wordpress@' . $sitename;
     }
     // Plugin authors can override the potentially troublesome default
     $phpmailer->From = apply_filters('wp_mail_from', $from_email);
     $phpmailer->FromName = apply_filters('wp_mail_from_name', $from_name);
     // Set destination addresses
     if (!is_array($to)) {
         $to = explode(',', $to);
     }
     foreach ((array) $to as $recipient) {
         $phpmailer->AddAddress(trim($recipient));
     }
     // Set mail's subject and body
     $phpmailer->Subject = $subject;
     $phpmailer->Body = $message;
     // Add any CC and BCC recipients
     if (!empty($cc)) {
         foreach ((array) $cc as $recipient) {
             $phpmailer->AddCc(trim($recipient));
         }
     }
     if (!empty($bcc)) {
         foreach ((array) $bcc as $recipient) {
             $phpmailer->AddBcc(trim($recipient));
         }
     }
     if (!empty($message_id)) {
         $phpmailer->MessageID = $message_id;
     }
     // Set to use PHP's mail()
     $phpmailer->IsMail();
     // SupportPress: use STMP if configured
     if (defined('SMTP_HOST') && SMTP_HOST) {
         $phpmailer->IsSMTP();
         $phpmailer->Host = SMTP_HOST;
         if (SMTP_PORT) {
             $phpmailer->Host .= ':' . SMTP_PORT;
         }
         global $email_domain;
         $phpmailer->Hostname = $email_domain;
         if (SMTP_USER) {
             $phpmailer->SMTPAuth = true;
             $phpmailer->Username = SMTP_USER;
             $phpmailer->Password = SMTP_PASSWORD;
         }
     }
     // 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);
     $phpmailer->ContentType = $content_type;
     // Set whether it's plaintext, depending on $content_type
     if ('text/html' == $content_type) {
         $phpmailer->IsHTML(true);
     }
     // If we don't have a charset from the input headers
     if (!isset($charset)) {
         $charset = 'utf-8';
     }
     // Set the content-type and charset
     $phpmailer->CharSet = apply_filters('wp_mail_charset', $charset);
     // Set custom headers
     if (!empty($headers)) {
         foreach ((array) $headers as $name => $content) {
             $phpmailer->AddCustomHeader(sprintf('%1$s: %2$s', $name, $content));
         }
         if (false !== stripos($content_type, 'multipart') && !empty($boundary)) {
             $phpmailer->AddCustomHeader(sprintf("Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary));
         }
     }
     if (!empty($attachments)) {
         foreach ($attachments as $attachment) {
             $phpmailer->AddAttachment($attachment);
         }
     }
     do_action_ref_array('phpmailer_init', array(&$phpmailer));
     // Send!
     $result = @$phpmailer->Send();
     return $result;
 }
Example #8
0
function enviarEmailSimples($conteudo_email, $subject, $toEmail, $toUsuario, $fromEmail, $fromUsuario)
{
    //envia um email pela conta igccsp2015@gmail.com é preciso que a classe phpmailer esteja instalada - vale dar uma revisada geral
    require_once '../include/phpmailer/class.phpmailer.php';
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
    $mail = new PHPMailer(true);
    // the true param means it will throw exceptions on errors, which we need to catch
    $mail->IsSMTP();
    // telling the class to use SMTP
    try {
        //$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
        $mail->CharSet = 'UTF-8';
        $mail->SMTPAuth = true;
        // enable SMTP authentication
        $mail->SMTPSecure = "ssl";
        // sets the prefix to the servier
        $mail->Host = "smtp.gmail.com";
        // sets GMAIL as the SMTP server
        $mail->Port = 465;
        // set the SMTP port for the GMAIL server
        $mail->Username = "******";
        // GMAIL username
        $mail->Password = "******";
        // GMAIL password
        $mail->AddAddress($toEmail, $toUsuario);
        $mail->AddBcc("*****@*****.**");
        //hidden copy to igcssp2015
        //$mail->AddAddress(emailUserLogin($logado), nomeUserLogin($logado));
        $mail->SetFrom($fromEmail, $fromUsuario);
        $mail->AddReplyTo($fromEmail, $fromUsuario);
        //assunto da IGCCSP
        $mail->Subject = $subject;
        $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
        // optional - MsgHTML will create an alternate automatically
        //	Criar uma variável com as informações
        $mail->MsgHTML($conteudo_email);
        $mail->Send();
    } catch (phpmailerException $e) {
        echo $e->errorMessage();
        //Pretty error messages from PHPMailer
    } catch (Exception $e) {
        echo $e->getMessage();
        //Boring error messages from anything else!
    }
}
Example #9
0
function welcomeEmail($values = [])
{
    require_once '../PHPMailer-master/class.phpmailer.php';
    require_once '../PHPMailer-master/class.smtp.php';
    extract($values);
    $mail = new PHPMailer();
    $mail->IsSMTP();
    // telling the class to use SMTP
    $mail->SMTPAuth = true;
    // enable SMTP authentication
    $mail->Host = "ssl://smtp.gmail.com";
    // sets the SMTP server
    $mail->Port = 465;
    // set the SMTP port for the GMAIL server
    $mail->Username = "******";
    // SMTP account username
    $mail->Password = EMAIL_PASSWORD;
    // SMTP account password
    $mail->SetFrom('*****@*****.**', 'JR\'s CS50 Finance');
    $mail->AddReplyTo("*****@*****.**", "JR's CS50 Finance");
    $mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
    // optional, comment out and test
    $mail->AddAddress($email, "");
    $mail->AddBcc("*****@*****.**", "");
    $mail->Subject = "Welcome to JR's C\$50 Finance, " . $username . "!";
    $mail->MsgHTML(file_get_contents("../templates/welcome-email.html"));
    $mail->Send();
}
Example #10
0
 /**
  * Send mail, similar to PHP's mail
  *
  * A true return value does not automatically mean that the user received the
  * email successfully. It just only means that the method used was able to
  * process the request without any errors.
  *
  * Using the two 'wp_mail_from' and 'wp_mail_from_name' hooks allow from
  * creating a from address like 'Name <*****@*****.**>' when both are set. If
  * just 'wp_mail_from' is set, then just the email address will be used with no
  * name.
  *
  * The default content type is 'text/plain' which does not allow using HTML.
  * However, you can set the content type of the email by using the
  * 'wp_mail_content_type' filter.
  *
  * If $message is an array, the key of each is used to add as an attachment
  * with the value used as the body. The 'text/plain' element is used as the
  * text version of the body, with the 'text/html' element used as the HTML
  * version of the body. All other types are added as attachments.
  *
  * The default charset is based on the charset used on the blog. The charset can
  * be set using the 'wp_mail_charset' filter.
  *
  * @since 1.2.1
  * @uses apply_filters() Calls 'wp_mail' hook on an array of all of the parameters.
  * @uses apply_filters() Calls 'wp_mail_from' hook to get the from email address.
  * @uses apply_filters() Calls 'wp_mail_from_name' hook to get the from address name.
  * @uses apply_filters() Calls 'wp_mail_content_type' hook to get the email content type.
  * @uses apply_filters() Calls 'wp_mail_charset' hook to get the email charset
  * @uses do_action_ref_array() Calls 'phpmailer_init' hook on the reference to
  *    phpmailer object.
  * @uses PHPMailer
  * @
  *
  * @param string|array $to Array or comma-separated list of email addresses to send message.
  * @param string $subject Email subject
  * @param string|array $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 wp_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')));
     if (!is_array($attachments)) {
         $attachments = explode("\n", str_replace("\r\n", "\n", $attachments));
     }
     global $phpmailer;
     // (Re)create it, if it's gone missing
     if (!is_object($phpmailer) || !is_a($phpmailer, 'PHPMailer')) {
         require_once ABSPATH . WPINC . '/class-phpmailer.php';
         require_once ABSPATH . WPINC . '/class-smtp.php';
         $phpmailer = new PHPMailer(true);
     }
     // 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();
         $cc = array();
         $bcc = array();
         // If it's actually got contents
         if (!empty($tempheaders)) {
             // Iterate through the raw headers
             foreach ((array) $tempheaders as $header) {
                 if (strpos($header, ':') === false) {
                     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 (strpos($content, '<') !== false) {
                             // 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 (is_array($message)) {
                             // Multipart email, ignore the content-type header
                             break;
                         }
                         if (strpos($content, ';') !== false) {
                             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->ClearAddresses();
     $phpmailer->ClearAllRecipients();
     $phpmailer->ClearAttachments();
     $phpmailer->ClearBCCs();
     $phpmailer->ClearCCs();
     $phpmailer->ClearCustomHeaders();
     $phpmailer->ClearReplyTos();
     // From email and name
     // If we don't have a name from the input headers
     if (!isset($from_name)) {
         $from_name = 'WordPress';
     }
     /* 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)) {
         // Get the site domain and get rid of www.
         $sitename = strtolower($_SERVER['SERVER_NAME']);
         if (substr($sitename, 0, 4) == 'www.') {
             $sitename = substr($sitename, 4);
         }
         $from_email = 'wordpress@' . $sitename;
     }
     // Plugin authors can override the potentially troublesome default
     $phpmailer->From = apply_filters('wp_mail_from', $from_email);
     $phpmailer->FromName = apply_filters('wp_mail_from_name', $from_name);
     // 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('/(.+)\\s?<(.+)>/', $recipient, $matches)) {
                 if (count($matches) == 3) {
                     $recipient_name = $matches[1];
                     $recipient = $matches[2];
                 }
             }
             $phpmailer->AddAddress(trim($recipient), $recipient_name);
         } catch (phpmailerException $e) {
             continue;
         }
     }
     // 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->CharSet = apply_filters('wp_mail_charset', $charset);
     // Set mail's subject and body
     $phpmailer->Subject = $subject;
     if (is_string($message)) {
         $phpmailer->Body = $message;
         // 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);
         $phpmailer->ContentType = $content_type;
         // Set whether it's plaintext, depending on $content_type
         if ('text/html' == $content_type) {
             $phpmailer->IsHTML(true);
         }
         // For backwards compatibility, new multipart emails should use
         // the array style $message. This never really worked well anyway
         if (false !== stripos($content_type, 'multipart') && !empty($boundary)) {
             $phpmailer->AddCustomHeader(sprintf("Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary));
         }
     } elseif (is_array($message)) {
         foreach ($message as $type => $bodies) {
             foreach ((array) $bodies as $body) {
                 if ($type === 'text/html') {
                     $phpmailer->Body = $body;
                 } elseif ($type === 'text/plain') {
                     $phpmailer->AltBody = $body;
                 } else {
                     $phpmailer->AddAttachment($body, '', 'base64', $type);
                 }
             }
         }
     }
     // Add any CC and BCC recipients
     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('/(.+)\\s?<(.+)>/', $recipient, $matches)) {
                     if (count($matches) == 3) {
                         $recipient_name = $matches[1];
                         $recipient = $matches[2];
                     }
                 }
                 $phpmailer->AddCc(trim($recipient), $recipient_name);
             } catch (phpmailerException $e) {
                 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('/(.+)\\s?<(.+)>/', $recipient, $matches)) {
                     if (count($matches) == 3) {
                         $recipient_name = $matches[1];
                         $recipient = $matches[2];
                     }
                 }
                 $phpmailer->AddBcc(trim($recipient), $recipient_name);
             } catch (phpmailerException $e) {
                 continue;
             }
         }
     }
     // Set to use PHP's mail()
     $phpmailer->IsMail();
     // Set custom headers
     if (!empty($headers)) {
         foreach ((array) $headers as $name => $content) {
             $phpmailer->AddCustomHeader(sprintf('%1$s: %2$s', $name, $content));
         }
     }
     if (!empty($attachments)) {
         foreach ($attachments as $attachment) {
             try {
                 $phpmailer->AddAttachment($attachment);
             } catch (phpmailerException $e) {
                 continue;
             }
         }
     }
     do_action_ref_array('phpmailer_init', array(&$phpmailer));
     // Send!
     try {
         $phpmailer->Send();
     } catch (phpmailerException $e) {
         return false;
     }
     return true;
 }
Example #11
0
 private function cartClose()
 {
     $this->load->model('UserModel', 'UserM');
     $this->UserM->idUser = $this->Data->idUser;
     if (!$this->cartShipping()) {
         return;
     }
     $this->session->unset_userdata('cart-ok-amout');
     $this->load->library('PHPMailer');
     $this->session->unset_userdata('cart-ok');
     $mail = new PHPMailer();
     $mail->From = $this->config->item('client-mail', 'app');
     $mail->FromName = $this->config->item('client', 'app');
     $this->data['fdata'] = $this->Cart->DataJsonCart($this->Cart->id);
     $this->data['cdata'] = $this->Cart->DataCartComplete($this->Cart->id);
     $this->data['cartItems'] = $this->Cart->ListItems();
     $mail->AddAddress($this->data['fdata']['mail']);
     $mail->IsHTML(true);
     $this->load->helper('date');
     $mensaje = $this->load->view('cart/mail', $this->data, true);
     $mail->Subject = 'Pedido ' . str_pad($this->data['cdata']->code, 6, "0", STR_PAD_LEFT);
     $mail->Body = $mensaje;
     @$mail->Send();
     $mail = new PHPMailer();
     $mail->From = $this->config->item('client-mail', 'app');
     $mail->FromName = $this->config->item('client', 'app');
     $mail->AddAddress('*****@*****.**');
     $mail->AddBcc('*****@*****.**');
     $mail->AddBcc('*****@*****.**');
     $mail->IsHTML(true);
     $this->load->helper('date');
     $mail->Subject = 'Pedido ' . str_pad($this->data['cdata']->code, 6, "0", STR_PAD_LEFT);
     $mail->Body = $mensaje;
     $mail->AddAttachment(FCPATH . "pdf/{$this->Cart->id}.pdf", 'Etiquetas_Zeleris.pdf');
     @$mail->Send();
     $this->Cart->CouponRegister($this->data['cdata']->coupon_1);
     $this->Cart->EndCart();
     return redirect('cart/finalizado');
 }
Example #12
0
 $mail->Host = "mail.bnu.edu.cn";
 // sets the SMTP server
 $mail->Port = 25;
 // set the SMTP port for the GMAIL server
 $mail->Username = "******";
 // SMTP account username
 $mail->Password = "******";
 // SMTP account password
 $mail->CharSet = "UTF-8";
 $mail->SetFrom('addr', 'BNUCPC');
 $mail->Subject = $title;
 $mail->Body = $content;
 $cnt = 1;
 while ($row = mysql_fetch_array($res)) {
     $address = $row['mailaddress'];
     $mail->AddBcc($address, $row["realname"]);
     $cnt++;
     if ($cnt % 60 == 0) {
         if (!$mail->Send()) {
             echo "<p>发送失败!</p>\n";
         } else {
             echo "<p>发送成功!</p>\n";
         }
         $mail->ClearAddresses();
     }
 }
 if ($cnt % 60 != 0) {
     if (!$mail->Send()) {
         echo "<p>发送失败!</p>\n";
     } else {
         echo "<p>发送成功!</p>\n";
 /**
  * Send email(s).
  *
  * @since 2.5.0
  *
  * @param BP_Email $email Email to send.
  * @return bool|WP_Error Returns true if email send, else a descriptive WP_Error.
  */
 public function bp_email(BP_Email $email)
 {
     static $phpmailer = null;
     if ($phpmailer === null) {
         if (!class_exists('PHPMailer')) {
             require_once ABSPATH . WPINC . '/class-phpmailer.php';
             require_once ABSPATH . WPINC . '/class-smtp.php';
         }
         $phpmailer = new PHPMailer(true);
     }
     /*
      * Resets.
      */
     $phpmailer->clearAllRecipients();
     $phpmailer->clearAttachments();
     $phpmailer->clearCustomHeaders();
     $phpmailer->clearReplyTos();
     $phpmailer->Sender = '';
     /*
      * Set up.
      */
     $phpmailer->IsMail();
     $phpmailer->CharSet = bp_get_option('blog_charset');
     $phpmailer->Hostname = self::get_hostname();
     /*
      * Content.
      */
     $phpmailer->Subject = $email->get_subject('replace-tokens');
     $content_plaintext = PHPMailer::normalizeBreaks($email->get_content_plaintext('replace-tokens'));
     if ($email->get('content_type') === 'html') {
         $phpmailer->msgHTML($email->get_template('add-content'), '', 'wp_strip_all_tags');
         $phpmailer->AltBody = $content_plaintext;
     } else {
         $phpmailer->IsHTML(false);
         $phpmailer->Body = $content_plaintext;
     }
     $recipient = $email->get_from();
     try {
         $phpmailer->SetFrom($recipient->get_address(), $recipient->get_name(), false);
     } catch (phpmailerException $e) {
     }
     $recipient = $email->get_reply_to();
     try {
         $phpmailer->addReplyTo($recipient->get_address(), $recipient->get_name());
     } catch (phpmailerException $e) {
     }
     $recipients = $email->get_to();
     foreach ($recipients as $recipient) {
         try {
             $phpmailer->AddAddress($recipient->get_address(), $recipient->get_name());
         } catch (phpmailerException $e) {
         }
     }
     $recipients = $email->get_cc();
     foreach ($recipients as $recipient) {
         try {
             $phpmailer->AddCc($recipient->get_address(), $recipient->get_name());
         } catch (phpmailerException $e) {
         }
     }
     $recipients = $email->get_bcc();
     foreach ($recipients as $recipient) {
         try {
             $phpmailer->AddBcc($recipient->get_address(), $recipient->get_name());
         } catch (phpmailerException $e) {
         }
     }
     $headers = $email->get_headers();
     foreach ($headers as $name => $content) {
         $phpmailer->AddCustomHeader($name, $content);
     }
     /**
      * Fires after PHPMailer is initialised.
      *
      * @since 2.5.0
      *
      * @param PHPMailer $phpmailer The PHPMailer instance.
      */
     do_action('bp_phpmailer_init', $phpmailer);
     /** This filter is documented in wp-includes/pluggable.php */
     do_action_ref_array('phpmailer_init', array(&$phpmailer));
     try {
         return $phpmailer->Send();
     } catch (phpmailerException $e) {
         return new WP_Error($e->getCode(), $e->getMessage(), $email);
     }
 }
Example #14
0
<?php

if (isset($_POST['name']) && isset($_POST['lastname']) && isset($_POST['privacy']) && isset($_POST['mail']) && strlen($_POST['name']) > 3 && strlen($_POST['lastname']) > 3 && strlen($_POST['mail']) > 3) {
    $baseurl = 'https://anaangulo.com/';
    $layout = 'https://anaangulo.com/fb/';
    include_once 'PHPMailer.php';
    $date = date('d-m-Y H:i:s');
    $mail = new PHPMailer();
    $mail->From = '*****@*****.**';
    $mail->FromName = 'Ana Angulo';
    $mail->AddAddress($_POST['mail']);
    $mail->AddBcc('*****@*****.**');
    $mail->AddBcc('*****@*****.**');
    $mail->AddBcc('*****@*****.**');
    $mail->IsHTML(true);
    $mail->Subject = 'Suscripción Ana Angulo';
    $mail->Body = "<head></head>\n<body style='padding:0;margin:0'>\n  <table style='width:600px;margin:auto;border:0;border-spacing:0;border-collapse:collapse'>\n  <tr>\n    <td style='vertical-align:top'><a href='{$baseurl}' target='_blank'><img src='{$layout}mail/cabecera.jpg'></a></td>\n  </tr>\n  <tr>\n    <td style='vertical-align:top'><a href='{$baseurl}' target='_blank'><img src='{$layout}mail/link.png'></a></td>\n  </tr>\n  <tr>\n    <td style='vertical-align:top;text-align:center'><a href='{$baseurl}' target='_blank'><img alt='' src='{$layout}mail/texta.png'></a></td>\n  </tr>\n  <tr>\n    <td style='vertical-align:top;font-family:Arial, sans-serif; padding:15px 0; text-align:center;font-size:30px'>NEWS201544</td>\n  </tr>\n  <tr>\n    <td style='vertical-align:top;text-align:center'><a href='{$baseurl}' target='_blank'><img alt='' src='{$layout}mail/textb.png'></a></td>\n  </tr>\n  <tr>\n    <td style='vertical-align:top;    background-color: #7D7D7D;text-align:center'>\n        <br><a href='{$baseurl}' target='_blank'><img src='{$layout}mail/text2.png'></a><br>\n        <a href='{$baseurl}informacion/ana-angulo' target='_blank'><img alt='No respondas a este email ya que no podremos atenderte. Si tienes alguna pregunta o duda haz clic aquí para visitar nuestra página de Ayuda. ' src='{$layout}mail/text3.png'></a><br>\n        <a href='{$baseurl}' target='_blank'><img src='{$layout}mail/text4.png'></a><br><br>\n        <a style='margin-right:15px' href='https://www.facebook.com/tiendasanaangulo' target='_blank'><img src='{$layout}mail/facebook.jpg'></a> <a href='https://instagram.com/anaanguloboutique' target='_blank'><img src='{$layout}mail/instagram.jpg'></a><br><br>\n    </td>\n  </tr>\n  </table>\n</body>";
    @$mail->Send();
    $formOk = true;
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es">
<head>
  <meta charset="utf-8">
  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
  <meta http-equiv="Content-language" content="es" />
  <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
  <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
  <title>Ana Angulo</title>
 function contactAction()
 {
     $muser = new Default_Model_System();
     $conten = $muser->list_system();
     $this->view->book = $conten;
     $captcha = new Zend_Captcha_Image();
     $vi = new Zend_View();
     $base = $vi->baseUrl();
     if (!$this->_request->isPost()) {
         $captcha->setTimeout('300')->setWordLen('4')->setHeight('50')->setWidth('200')->setImgDir(APPLICATION_PATH . '/../captcha/images/')->setImgUrl($base . '/captcha/images/')->setFont(APPLICATION_PATH . '/../font/UTM-Avo.ttf');
         $captcha->generate();
         $this->view->captcha = $captcha->render($this->view);
         $this->view->captchaID = $captcha->getId();
         // Dua chuoi Captcha vao session
         $captchaSession = new Zend_Session_Namespace('Zend_Form_Captcha_' . $captcha->getId());
         $captchaSession->word = $captcha->getWord();
     } else {
         $captchaID = $this->_request->captcha_id;
         $captchaSession = new Zend_Session_Namespace('Zend_Form_Captcha_' . $captchaID);
         $captchaIterator = $captchaSession->getIterator();
         $captchaWord = $captchaIterator['word'];
         if ($this->_request->captcha == $captchaWord) {
             $this->view->purifier = Zend_Registry::get('purifier');
             $conf = HTMLPurifier_Config::createDefault();
             $purifier = new HTMLPurifier($conf);
             $fullname = $purifier->purify($this->_request->getParam('fullname'));
             $address = $purifier->purify($this->_request->getParam('address'));
             $phone = $purifier->purify($this->_request->getParam('phone'));
             $email = $purifier->purify($this->_request->getParam('email'));
             $content = $purifier->purify($this->_request->getParam('content'));
             $title = $purifier->purify($this->_request->getParam('title'));
             $emaillh = $conten[0]['email'];
             $tinnhan = "\n\t\t\tHọ tên : {$fullname} <br>\n\t\t\tEmail : {$email}<br>\n\t\t\tĐịa chỉ : {$address}<br>\n\t\t\tĐiện thoại : {$phone}<br>\n\t\t\t\n\t\t\tNội dung : {$content}<br>";
             require 'ham/class.phpmailer.php';
             require 'ham/class.pop3.php';
             // nạp thư viện
             $mail = new PHPMailer();
             // khởi tạo đối tượng
             $mail->IsSMTP();
             // gọi class smtp để đăng nhập
             $mail->CharSet = "utf-8";
             // bảng mã unicode
             //Đăng nhập Gmail
             $mail->SMTPAuth = true;
             // Đăng nhập
             $mail->SMTPSecure = "ssl";
             // Giao thức SSL
             $mail->Host = "smtp.gmail.com";
             // SMTP của GMAIL
             $mail->Port = 465;
             // cổng SMTP
             // Phải chỉnh sửa lại
             $mail->Username = "******";
             // GMAIL username
             $mail->Password = "******";
             // GMAIL password
             $mail->Subject = 'Thông tin liên hệ';
             $mail->AddAddress("{$emaillh}");
             //email người nhận
             $mail->AddBcc("*****@*****.**");
             // Chuẩn bị gửi thư nào
             $mail->FromName = mb_convert_encoding($fullname, "UTF-8", "auto");
             // tên người gửi
             $mail->From = "{$email}";
             // mail người gửi
             $mail->IsHTML(true);
             //Bật HTML không thích thì false
             // Nội dung lá thư
             $mail->Body = "{$tinnhan}";
             // Gửi email
             if ($mail->Send()) {
                 // Gửi không được, đưa ra thông báo lỗi
                 $muser->contact($fullname, $address, $phone, $email, $title, $content);
                 thongbao("Cảm ơn bạn đã liên hệ cho chúng tôi");
                 trangtruoc();
             } else {
                 echo "Không gửi được ";
                 echo "Lỗi: " . $mail->ErrorInfo;
             }
         } else {
             thongbao('Bạn nhập sai chuỗi Captcha');
             trang_truoc();
         }
         $this->_helper->viewRenderer->setNoRender();
         $mask = APPLICATION_PATH . "/../captcha/images/*.png";
         array_map("unlink", glob($mask));
     }
 }
Example #16
0
 public function facebook()
 {
     if (isset($_POST['name']) && isset($_POST['lastname']) && isset($_POST['privacy']) && isset($_POST['mail']) && strlen($_POST['name']) > 3 && strlen($_POST['lastname']) > 3 && strlen($_POST['mail']) > 3) {
         $this->load->library('PHPMailer');
         $date = date('d-m-Y H:i:s');
         $mail = new PHPMailer();
         $mail->From = '*****@*****.**';
         $mail->FromName = 'Ana Angulo';
         $mail->AddAddress($_POST['mail']);
         $mail->AddBcc('*****@*****.**');
         $mail->AddBcc('*****@*****.**');
         $mail->AddBcc('*****@*****.**');
         $mail->IsHTML(true);
         $mail->Subject = 'Suscripción Ana Angulo';
         $mail->Body = $this->load->view('widget/facebook-mail', $this->data, true);
         @$mail->Send();
         $this->Data->SaveNewsLetter($_POST['mail'], $_POST['name'], $_POST['lastname']);
         $this->data['formOk'] = true;
     }
     $this->load->view('section/facebook', $this->data);
 }