예제 #1
0
 function sendPlain($to, $from, $subject, $plainContent, $attachedFiles = false, $customheaders = false)
 {
     $mail = new SendGrid\Email();
     $sendgrid = $this->instanciate();
     $to = explode(',', $to);
     foreach ($to as $s1) {
         $mail->addTo(trim($s1));
     }
     $mail->setFrom(trim($from));
     $mail->setSubject($subject);
     $mail->setText($plainContent);
     $sendgrid->send($mail);
 }
예제 #2
0
 protected function sendEmail($to, $subj, $text, $html = null)
 {
     $email = new \SendGrid\Email();
     $email->addCategory($subj);
     $email->addTo($to);
     $email->setFrom('*****@*****.**');
     $email->setFromName('Edge conf');
     $email->setSubject($subj);
     $email->setText($text);
     if ($html) {
         $emogrifier = new \Pelago\Emogrifier($html, file_get_contents(realpath(__DIR__ . '/../../../public/css/email.css')));
         $email->setHtml($emogrifier->emogrify());
     }
     $sendgrid = new \SendGrid($this->app->config->sendgrid->username, $this->app->config->sendgrid->password);
     $resp = $sendgrid->send($email);
 }
예제 #3
0
 public function testSetText()
 {
     $email = new \SendGrid\Email();
     $text = 'sample plain text';
     $email->setText($text);
     $this->assertEquals($text, $email->getText());
 }
예제 #4
0
파일: Mail.php 프로젝트: josephsnyder/Midas
 /**
  * Send the mail.
  *
  * @param Midas_Mail $mail mail instance
  * @throws Midas_Service_SendGrid_Exception
  */
 public function sendMail(Midas_Mail $mail)
 {
     if (is_null($this->_client)) {
         $this->_client = new \SendGrid($this->_user, $this->_key, $this->_config);
     }
     $email = new \SendGrid\Email();
     $email->setBccs($mail->getBcc());
     $email->setCcs($mail->getCc());
     $email->setHtml($mail->getBodyHtml(true));
     $email->setFrom($mail->getFrom());
     $email->setReplyTo($mail->getReplyTo());
     $email->setSubject($mail->getSubject());
     $email->setText($mail->getBodyText(true));
     $email->setTos($mail->getTo());
     try {
         $this->_client->send($email);
     } catch (\SendGrid\Exception $exception) {
         throw new Midas_Service_SendGrid_Exception('Could not send mail');
     }
 }
예제 #5
0
 public function send(array $options)
 {
     $connection = $this->getConnection();
     $email = new \SendGrid\Email();
     $options = array_replace_recursive($this->defaults, $options);
     foreach ((array) $options['to'] as $to) {
         $email->addTo($to);
     }
     foreach ((array) $options['cc'] as $cc) {
         $email->addCc($cc);
     }
     foreach ((array) $options['bcc'] as $bcc) {
         $email->addBcc($bcc);
     }
     $email->setSubject($options['subject']);
     $email->setFrom($this->getFrom($options));
     if (!empty($options['category'])) {
         $email->setCategory($options['category']);
     }
     if (!empty($options['categories'])) {
         $email->setCategories($options['categories']);
     }
     if (!empty($options['text'])) {
         $email->setText($options['text']);
     }
     if (!empty($options['html'])) {
         $email->setHtml($options['html']);
     } elseif (!empty($options['layout']) && !empty($options['data'])) {
         $path = $this->_app->basePath . '/mail/sendgrid/' . $options['layout'] . '.html';
         if (!file_exists($path)) {
             $message = 'Layout "' . $options['layout'] . '" cannot be found in "/mail/sendgrid/".';
             if ($this->_version == 2) {
                 throw new \yii\web\NotFoundHttpException($message);
             } else {
                 throw new \CHttpException(404, $message);
             }
         }
         $params = array('subject' => $options['subject']);
         foreach ($options['data'] as $key => $value) {
             $params['{{' . $key . '}}'] = $value;
         }
         $html = file_get_contents($path);
         $html = strtr($html, $params);
         $email->setHtml($html);
     }
     return $response = $connection->send($email);
 }
예제 #6
0
 /**
  * Set text contents.
  *
  * @param SendGrid\Email $email
  * @param Swift_Mime_Message $message
  */
 protected function setText($email, Swift_Mime_Message $message)
 {
     foreach ($message->getChildren() as $attachment) {
         if (!$attachment instanceof Swift_MimePart) {
             continue;
         }
         $email->setText($attachment->getBody());
     }
 }
 /**
  * Repair data for send message
  *
  * @param array $args
  *
  * @return array
  */
 function generate_postdata($args = array())
 {
     $emailData = new SendGrid\Email();
     $is_force = aem_get_option('aem_force_header', FALSE);
     $header = $this->process_header($args['headers']);
     /**
      * generate postFile
      */
     $emailData->setSubject($args['subject']);
     $emailData->setText($args['subject']);
     //From email
     if (!$is_force && isset($header['from_name'])) {
         $from_email = $header['from_email'];
     } else {
         $from_email = AEM_Option()->get_from_email();
     }
     $from_email = apply_filters('wp_mail_from', $from_email);
     $emailData->setFrom($from_email);
     //From name
     if (!$is_force && isset($header['from_name'])) {
         $from_name = $header['from_name'];
     } else {
         $from_name = AEM_Option()->get_from_name();
     }
     $from_name = apply_filters('wp_mail_from_name', $from_name);
     $emailData->setFromName($from_name);
     //to
     if (!is_array($args['to'])) {
         $args['to'] = explode(',', $args['to']);
     }
     foreach ((array) $args['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];
                 }
             }
             $emailData->addTo($recipient, $recipient_name);
         } catch (phpmailerException $e) {
             continue;
         }
     }
     //cc
     if (!empty($header['cc'])) {
         //header cc not empty
         if (empty($args['cc'])) {
             //arg cc empty, override agr cc
             $args['cc'] = $header['cc'];
         } else {
             //arg cc not empty
             if (!is_array($args['cc'])) {
                 $args['cc'] = explode(',', $args['cc']);
             }
             //merge them
             $args['cc'] = array_merge($header['cc']);
         }
     }
     if (!empty($args['cc'])) {
         foreach ((array) $args['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];
                     }
                 }
                 $emailData->addCc($recipient);
             } catch (phpmailerException $e) {
                 continue;
             }
         }
     }
     //bcc
     if (!empty($header['bcc'])) {
         //header bcc not empty
         if (empty($args['bcc'])) {
             //arg bcc empty, override agr cc
             $args['bcc'] = $header['bcc'];
         } else {
             //arg bcc not empty
             if (!is_array($args['bcc'])) {
                 $args['bcc'] = explode(',', $args['bcc']);
             }
             //merge them
             $args['bcc'] = array_merge($header['bcc']);
         }
     }
     if (!empty($args['bcc'])) {
         foreach ((array) $args['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];
                     }
                 }
                 $emailData->addBcc($recipient);
             } catch (Exception $e) {
                 continue;
             }
         }
     }
     if (!isset($header['content_type'])) {
         $content_type = 'text/plain';
     } else {
         $content_type = $header['content_type'];
     }
     $content_type = apply_filters('wp_mail_content_type', $content_type);
     if ($content_type == "text/html") {
         $emailData->setHtml($args['message']);
     }
     //custom header
     if (isset($args['headers']) && is_array($args['headers'])) {
         //extract header line
         $header_arr = explode("\r\n", $args['headers']);
         foreach ($header_arr as $header) {
             //extract header key:value
             $tmp = explode(':', $header);
             if (count($tmp) > 1) {
                 if ($tmp[1] != NULL) {
                     if (strtolower($tmp[0]) == 'from') {
                         if (aem_get_option('aem_force_header')) {
                             continue;
                         }
                     }
                     $emailData->addHeader($tmp[0], $tmp[1]);
                 }
             }
         }
     }
     //$args['attachments'] = array ( plugin_dir_path( AEM_PLUGIN_FILE )."/inc/ae/assets/img/slider.png" );
     if (!empty($args['attachments'])) {
         $emailData->setAttachments($args['attachments']);
     }
     $postData = apply_filters("aem_postdata", $emailData);
     return $postData;
 }