1

我在 Rackspace 上运行一个云应用程序(使用 CakePHP),我想使用 cakephp 发送电子邮件。我用这个:https ://github.com/kochb/cakephp-mailgun 但它返回给我一个

 "Could not send email.

Error: An Internal Error Has Occurred." 

错误。我尝试发送电子邮件的方式是使用以下代码:

$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'));

我已经编辑了插入 MailGun API 凭据等的 Config/Email.php 文件。

可能发生了什么?你能找出为什么会这样吗?

提前致谢!

4

1 回答 1

1

(我遇到了和你一样的错误)

BasicTransport没有正确的“预处理”,也没有适当的响应处理。

我从那里复制了功能,CurlTransport现在它对我有用。

具体来说,我们需要:

    $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;
        }
    }

接着:

    $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);
    }
于 2013-11-21T22:56:53.713 回答