Пример #1
0
 private function compose($send = true)
 {
     $components = array('subject' => $this->get('subject', true), 'sender' => $this->get('sender', true), 'body' => $this->get('body', true), 'recipient' => $this->get('recipient', true), 'additional_headers' => $this->get('additional_headers', true), 'attachments' => $this->attachments());
     $components = apply_filters('wpcf7_mail_components', $components, wpcf7_get_current_contact_form(), $this);
     if (!$send) {
         return $components;
     }
     $subject = wpcf7_strip_newline($components['subject']);
     $sender = wpcf7_strip_newline($components['sender']);
     $recipient = wpcf7_strip_newline($components['recipient']);
     $body = $components['body'];
     $additional_headers = trim($components['additional_headers']);
     $attachments = $components['attachments'];
     $headers = "From: {$sender}\n";
     if ($this->use_html) {
         $headers .= "Content-Type: text/html\n";
         $headers .= "X-WPCF7-Content-Type: text/html\n";
     } else {
         $headers .= "X-WPCF7-Content-Type: text/plain\n";
     }
     if ($additional_headers) {
         $headers .= $additional_headers . "\n";
     }
     return wp_mail($recipient, $subject, $body, $headers, $attachments);
 }
Пример #2
0
 private function compose($send = true)
 {
     $template = $this->template;
     $use_html = (bool) $template['use_html'];
     $subject = $this->replace_tags($template['subject']);
     $sender = $this->replace_tags($template['sender']);
     $recipient = $this->replace_tags($template['recipient']);
     $additional_headers = $this->replace_tags($template['additional_headers']);
     if ($use_html) {
         $body = $this->replace_tags($template['body'], true);
         $body = wpautop($body);
     } else {
         $body = $this->replace_tags($template['body']);
     }
     $attachments = $this->attachments($template['attachments']);
     $components = compact('subject', 'sender', 'body', 'recipient', 'additional_headers', 'attachments');
     $components = apply_filters('wpcf7_mail_components', $components, wpcf7_get_current_contact_form());
     extract($components);
     $subject = wpcf7_strip_newline($subject);
     $sender = wpcf7_strip_newline($sender);
     $recipient = wpcf7_strip_newline($recipient);
     $headers = "From: {$sender}\n";
     if ($use_html) {
         $headers .= "Content-Type: text/html\n";
     }
     $additional_headers = trim($additional_headers);
     if ($additional_headers) {
         $headers .= $additional_headers . "\n";
     }
     if ($send) {
         return @wp_mail($recipient, $subject, $body, $headers, $attachments);
     }
     $components = compact('subject', 'sender', 'body', 'recipient', 'headers', 'attachments');
     return $components;
 }
 function submission($components, $contact_form, $mail)
 {
     global $wpcf7s_post_id;
     $contact_form_id = 0;
     if (method_exists($contact_form, 'id')) {
         $contact_form_id = $contact_form->id();
     } elseif (property_exists($contact_form, 'id')) {
         $contact_form_id = $contact_form->id;
     }
     $body = $components['body'];
     $sender = wpcf7_strip_newline($components['sender']);
     $recipient = wpcf7_strip_newline($components['recipient']);
     $subject = wpcf7_strip_newline($components['subject']);
     $headers = trim($components['additional_headers']);
     $attachments = $components['attachments'];
     $submission = array('form_id' => $contact_form_id, 'body' => $body, 'sender' => $sender, 'subject' => $subject, 'recipient' => $recipient, 'additional_headers' => $headers, 'attachments' => $attachments);
     if (!empty($wpcf7s_post_id)) {
         $submission['parent'] = $wpcf7s_post_id;
     }
     $post_id = $this->save($submission);
     if (empty($wpcf7s_post_id)) {
         $wpcf7s_post_id = $post_id;
     }
     return $components;
 }
 public function validate_mail($template = 'mail')
 {
     $components = (array) $this->contact_form->prop($template);
     if (!$components) {
         return;
     }
     if ('mail' != $template && empty($components['active'])) {
         return;
     }
     $components = wp_parse_args($components, array('subject' => '', 'sender' => '', 'recipient' => '', 'additional_headers' => '', 'body' => ''));
     $callback = array($this, 'replace_mail_tags_with_minimum_input');
     $subject = $components['subject'];
     $subject = new WPCF7_MailTaggedText($subject, array('callback' => $callback));
     $subject = $subject->replace_tags();
     $subject = wpcf7_strip_newline($subject);
     if ('' === $subject) {
         $this->add_error(sprintf('%s.subject', $template), self::error_maybe_empty);
     }
     $sender = $components['sender'];
     $sender = new WPCF7_MailTaggedText($sender, array('callback' => $callback));
     $sender = $sender->replace_tags();
     $sender = wpcf7_strip_newline($sender);
     if (!wpcf7_is_mailbox_list($sender)) {
         $this->add_error(sprintf('%s.sender', $template), self::error_invalid_syntax);
     } elseif (!wpcf7_is_email_in_site_domain($sender)) {
         $this->add_error(sprintf('%s.sender', $template), self::error_email_not_in_site_domain);
     }
     $recipient = $components['recipient'];
     $recipient = new WPCF7_MailTaggedText($recipient, array('callback' => $callback));
     $recipient = $recipient->replace_tags();
     $recipient = wpcf7_strip_newline($recipient);
     if (!wpcf7_is_mailbox_list($recipient)) {
         $this->add_error(sprintf('%s.recipient', $template), self::error_invalid_syntax);
     }
     $additional_headers = $components['additional_headers'];
     $additional_headers = new WPCF7_MailTaggedText($additional_headers, array('callback' => $callback));
     $additional_headers = $additional_headers->replace_tags();
     if (!$this->test_additional_headers_syntax($additional_headers)) {
         $this->add_error(sprintf('%s.additional_headers', $template), self::error_invalid_syntax);
     }
     $body = $components['body'];
     $body = new WPCF7_MailTaggedText($body, array('callback' => $callback));
     $body = $body->replace_tags();
     if ('' === $body) {
         $this->add_error(sprintf('%s.body', $template), self::error_maybe_empty);
     }
 }
Пример #5
0
 public function compose_mail($mail_template, $send = true)
 {
     $this->mail_template_in_process = $mail_template;
     $use_html = (bool) $mail_template['use_html'];
     $subject = $this->replace_mail_tags($mail_template['subject']);
     $sender = $this->replace_mail_tags($mail_template['sender']);
     $recipient = $this->replace_mail_tags($mail_template['recipient']);
     $additional_headers = $this->replace_mail_tags($mail_template['additional_headers']);
     if ($use_html) {
         $body = $this->replace_mail_tags($mail_template['body'], true);
         $body = wpautop($body);
     } else {
         $body = $this->replace_mail_tags($mail_template['body']);
     }
     $attachments = $this->mail_attachments($mail_template['attachments']);
     $components = compact('subject', 'sender', 'body', 'recipient', 'additional_headers', 'attachments');
     $components = apply_filters_ref_array('wpcf7_mail_components', array($components, &$this));
     extract($components);
     $subject = wpcf7_strip_newline($subject);
     $sender = wpcf7_strip_newline($sender);
     $recipient = wpcf7_strip_newline($recipient);
     $headers = "From: {$sender}\n";
     if ($use_html) {
         $headers .= "Content-Type: text/html\n";
     }
     $additional_headers = trim($additional_headers);
     if ($additional_headers) {
         $headers .= $additional_headers . "\n";
     }
     if ($send) {
         return @wp_mail($recipient, $subject, $body, $headers, $attachments);
     }
     return compact('subject', 'sender', 'body', 'recipient', 'headers', 'attachments');
 }
Пример #6
0
 public function validate_mail($template = 'mail')
 {
     $components = (array) $this->contact_form->prop($template);
     if (!$components) {
         return;
     }
     if ('mail' != $template && empty($components['active'])) {
         return;
     }
     $components = wp_parse_args($components, array('subject' => '', 'sender' => '', 'recipient' => '', 'additional_headers' => '', 'body' => ''));
     $callback = array($this, 'replace_mail_tags_with_minimum_input');
     $subject = $components['subject'];
     $subject = new WPCF7_MailTaggedText($subject, array('callback' => $callback));
     $subject = $subject->replace_tags();
     $subject = wpcf7_strip_newline($subject);
     if ('' === $subject) {
         $this->add_error(sprintf('%s.subject', $template), self::error_maybe_empty, array('link' => __('http://contactform7.com/configuration-errors/#mail.subject:error_maybe_empty', 'contact-form-7')));
     }
     $sender = $components['sender'];
     $sender = new WPCF7_MailTaggedText($sender, array('callback' => $callback));
     $sender = $sender->replace_tags();
     $sender = wpcf7_strip_newline($sender);
     if (!wpcf7_is_mailbox_list($sender)) {
         $this->add_error(sprintf('%s.sender', $template), self::error_invalid_syntax, array('link' => __('http://contactform7.com/configuration-errors/#mail.sender:error_invalid_syntax', 'contact-form-7')));
     } elseif (!wpcf7_is_email_in_site_domain($sender)) {
         $this->add_error(sprintf('%s.sender', $template), self::error_email_not_in_site_domain, array('link' => __('http://contactform7.com/configuration-errors/#mail.sender:error_email_not_in_site_domain', 'contact-form-7')));
     }
     $recipient = $components['recipient'];
     $recipient = new WPCF7_MailTaggedText($recipient, array('callback' => $callback));
     $recipient = $recipient->replace_tags();
     $recipient = wpcf7_strip_newline($recipient);
     if (!wpcf7_is_mailbox_list($recipient)) {
         $this->add_error(sprintf('%s.recipient', $template), self::error_invalid_syntax, array('link' => __('http://contactform7.com/configuration-errors/#mail.recipient:error_invalid_syntax', 'contact-form-7')));
     }
     $additional_headers = $components['additional_headers'];
     $additional_headers = new WPCF7_MailTaggedText($additional_headers, array('callback' => $callback));
     $additional_headers = $additional_headers->replace_tags();
     $additional_headers = explode("\n", $additional_headers);
     $mailbox_header_types = array('reply-to', 'cc', 'bcc');
     foreach ($additional_headers as $header) {
         $header = trim($header);
         if ('' === $header) {
             continue;
         }
         if (!preg_match('/^([0-9A-Za-z-]+):(.+)$/', $header, $matches)) {
             $this->add_error(sprintf('%s.additional_headers', $template), self::error_invalid_syntax, array('link' => __('http://contactform7.com/configuration-errors/#mail.additional_headers:error_invalid_syntax', 'contact-form-7')));
         } elseif (in_array(strtolower($matches[1]), $mailbox_header_types) && !wpcf7_is_mailbox_list($matches[2])) {
             $this->add_error(sprintf('%s.additional_headers', $template), self::error_invalid_syntax, array('message' => __("The %name% field value is invalid.", 'contact-form-7'), 'params' => array('name' => $matches[1]), 'link' => __('http://contactform7.com/configuration-errors/#mail.additional_headers:error_invalid_syntax', 'contact-form-7')));
         }
     }
     $body = $components['body'];
     $body = new WPCF7_MailTaggedText($body, array('callback' => $callback));
     $body = $body->replace_tags();
     if ('' === $body) {
         $this->add_error(sprintf('%s.body', $template), self::error_maybe_empty, array('link' => __('http://contactform7.com/configuration-errors/#mail.body:error_maybe_empty', 'contact-form-7')));
     }
 }