private function SendByMailGun()
 {
     $mg = $this->config['mailgun'];
     $api_key = $mg['apiKey'];
     /* Api Key got from https://mailgun.com/cp/my_account */
     $domain = $mg['domain'];
     /* Domain Name you given to Mailgun*/
     if (empty($this->ReplyTo)) {
         $this->ReplyTo = $this->From;
         $this->ReplyToName = $this->FromName;
     }
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
     curl_setopt($ch, CURLOPT_USERPWD, "api:" . $api_key);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
     curl_setopt($ch, CURLOPT_URL, "https://api.mailgun.net/v3/" . $domain . "/messages");
     $fields = array("from" => (empty($this->FromName) ? $mg['fromName'] : $this->FromName) . " <" . $mg['fromEmail'] . ">", "to" => $this->TO, "subject" => $this->Subject, "h:Reply-To" => $this->ReplyToName . " <" . $this->ReplyTo . ">", "html" => $this->Body);
     // php 5.5+
     if (class_exists("\\CURLFile")) {
         // process inline images
         $result = $this->extractEmbededImages($this->Body);
         if (!empty($result['imgFiles'])) {
             $fields['html'] = $result['message'];
             $inlines = $this->mailgunAddFiles($result['imgFiles'], 'inline');
             $fields = array_merge($fields, $inlines);
         }
         // process normal attachments
         $attachments = Form::getAttachments();
         $fields = array_merge($fields, $this->mailgunAddFiles($attachments, 'attachment'));
     }
     if (!empty($this->CC)) {
         $fields['cc'] = $this->CC;
     }
     if (!empty($this->BCC)) {
         $fields['bcc'] = $this->BCC;
     }
     curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
     $result = curl_exec($ch);
     $this->isSent = $result ? true : false;
     $this->sentMIMEMessage = "CURL paramenters:\n" . var_export($fields, true) . "\n" . var_export($result, true);
     if (!$this->isSent) {
         $this->sendError = curl_error($ch);
     }
     curl_close($ch);
     return $this->isSent;
 }
Example #2
0
 private function SendByMailGun()
 {
     $mg = $this->config['mailgun'];
     $api_key = $mg['apiKey'];
     /* Api Key got from https://mailgun.com/cp/my_account */
     $domain = $mg['domain'];
     /* Domain Name you given to Mailgun*/
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
     curl_setopt($ch, CURLOPT_USERPWD, "api:" . $api_key);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
     curl_setopt($ch, CURLOPT_URL, "https://api.mailgun.net/v3/" . $domain . "/messages");
     $fields = array("from" => $mg['fromName'] . " <" . $mg['fromEmail'] . ">", "to" => $this->TO, "subject" => $this->Subject, "h:Reply-To" => $this->FromName . " <" . $this->From . ">", "html" => $this->Body);
     // php 5.5+
     if (class_exists("\\CURLFile")) {
         $attachments = Form::getAttachments();
         if (is_array($attachments)) {
             $n = count($attachments);
             for ($i = 0; $i < $n; $i++) {
                 $f = $attachments[$i];
                 $key = "attachment" . ($i == 0 ? '' : "[{$i}]");
                 $fields[$key] = new \CURLFile($f['path'], null, basename($f['name']));
             }
         }
     }
     if (!empty($this->CC)) {
         $fields['cc'] = $this->CC;
     }
     if (!empty($this->BCC)) {
         $fields['bcc'] = $this->BCC;
     }
     curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
     $result = curl_exec($ch);
     $this->isSent = $result ? true : false;
     $this->sentMIMEMessage = "CURL paramenters:\n" . var_export($fields, true) . "\n" . var_export($result, true);
     if (!$this->isSent) {
         $this->sendError = curl_error($ch);
     }
     curl_close($ch);
     return $this->isSent;
 }