ItGo.me Focus on IT Recommend

Home > email - Send mail via MailGun in CakePHP

email - Send mail via MailGun in CakePHP

2020腾讯云双十一活动,全年最低!!!(领取3500元代金券),
地址https://cloud.tencent.com/act/cps/redirect?redirect=1073

2020阿里云最低价产品入口,含代金券(新老用户有优惠),
入口地址https://www.aliyun.com/minisite/goods

i run a cloud app (using CakePHP) on Rackspace and i wanna send emails using cakephp. I used this: https://github.com/kochb/cakephp-mailgun but it returns me an

 "Could not send email.

Error: An Internal Error Has Occurred." 

error. The way i try to send an email is with the following code:

$Email = new CakeEmail();


          $from = $this->request->data['Mail']['from'];
          $to = ($this->request->data['Mail']['to']);
          $subject = $this->request->data['Mail']['subject'];
          $message = $this->request->data['Mail']['message'];

                $Email->sender($from, 'TestName');
                $Email->from($from)
                    ->bcc($to)  
                    ->replyTo($from)
                    ->subject($subject)
                    ->send($message);



                    $this->Session->setFlash('On the way to recipient');
                    $this->redirect(array('action' => 'index'));

I have edited the Config/Email.php file inserting the MailGun API credentials etc.

What's possibly going on? Can you find out why this happens?

Thanks in advance!

email cakephp mailgun
|
  this question
asked Aug 5 '13 at 18:21 Kostas Livieratos 325 8 24 1   Can you try defining the "from", "to", "subject", etc by hand? I literally copied your example, but set those parameters, and the message sent without issue. Here's a Gist. –  Travis Swientek Aug 5 '13 at 22:15

 | 

1 Answers
1

---Accepted---Accepted---Accepted---

(I was having the same errors you were)

The BasicTransport didn't have the right "pre-processing" nor the appropriate response handling.

Recommend:email - How to send mail only to bcc with mailgun php API

EQUEST, 'POST'); curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v2/'.$domain.'/messages'); curl_setopt($ch, CURLOPT_POSTFIELDS, array( 'from' => 'Example <examle@examle.com>', 'to' => $email, 'bcc' => $bcc, '

I copied over the functionality from CurlTransport and it works for me now.

Specifically, we needed:

    $post = array();
    $post_preprocess = array_merge(
        $email->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc', 'subject')),
        array(
            'text' => $email->message(CakeEmail::MESSAGE_TEXT),
            'html' => $email->message(CakeEmail::MESSAGE_HTML)
        )
    );
    foreach ($post_preprocess as $k => $v) {
        if (! empty($v)) {
            $post[strtolower($k)] = $v;
        }
    }

and then:

    $response = $http->post($url, $post, $request);
    if ($response === false) {
        throw new SocketException("Mailgun BasicTransport error, no response", 500);
    }

    $http_status = $response->code;
    if ($http_status != 200) {
        throw new SocketException("Mailgun request failed.  Status: $http_status, Response: {$response->body}", 500);
    }

|
  this answer
answered Nov 21 '13 at 22:56 zeroasterisk 1,630 17 25

 | 

Recommend:api - Swift Send Email with MailGun

rch So Far As I understand it, there are two methods to send an email via MailGun. One is to email MailGun with the emails, and MailGun will redirect it (See Send via SMTP). That will, as I understand it, not work, as iOS cannot programatic

------splitte line----------------------------