CakeEmail循环不发送

时间:2014-09-22 19:47:26

标签: php email cakephp-2.4 cakeemail

我有一个使用CakeEmail发送电子邮件的应用。如果我发送一封电子邮件并且我可以在我的收件箱中查看该电子邮件,它可以100%正常工作,它看起来应该是应该的。

现在,当我将相同的发送位置于循环中,并使用唯一键遍历数组并尝试发送它时,它甚至不会发送一封电子邮件。

这是我的功能:

public function _email($data = null) {
    if ($data == null) {
        throw new NotFoundException(__('Invalid invite'));
    }
    if(count($data) == 1) {
        $data[0] = $data;
        unset($data['Invite']);
    }
    $email = new CakeEmail();
    foreach($data as $invite) {
        $this->Invite->id = $invite['Invite']['id'];
        $email->reset();
        $email->from(array('invites@example.co.za'=>'Invite'));
        $email->replyTo(array('replytoaddress@gmail.com'));
        $email->subject('subject');
        $email->to(array($invite['Invite']['email'] => $invite['Invite']['name']));
        $email->viewVars(array('key'=>$invite['Invite']['passkey'],'id'=>$invite['Invite']['id']));
        $email->template('default');
        $email->emailFormat('html');
        $email->send();
    }
    $this->Session->setFlash("Invite(s) sent out.");
    $this->redirect(array("action"=>"index"));
}

如上所述,如果我将1个数组传递给它,就会发送:

array(
    'Invite' => array(
        'id' => '13',
        'passkey' => '207ac02e711ec6c09c0e86e7af676e18d7f14308',
        'name' => 'Some Person',
        'email' => 'example@email.com',
        'partner' => '',
        'sent' => false,
        'response' => 'Pending',
        'created' => '2014-09-22 21:44:07',
        'modified' => '2014-09-22 21:44:07'
    )
)

然而不止一个如下,它失败并没有错误。

array(
    (int) 0 => array(
        'Invite' => array(
            'id' => '13',
            'passkey' => '207ac02e711ec6c09c0e86e7af676e18d7f14308',
            'name' => 'Some Person',
            'email' => 'example@email.com',
            'partner' => '',
            'sent' => false,
            'response' => 'Pending',
            'created' => '2014-09-22 21:44:07',
            'modified' => '2014-09-22 21:44:07'
        )
    ),
    (int) 1 => array(
        'Invite' => array(
            'id' => '14',
            'passkey' => '03fd8bdb6d91f2a30963034ff9e56317e3894eeb',
            'name' => 'another person',
            'email' => 'another@example.com',
            'partner' => '',
            'sent' => false,
            'response' => 'Pending',
            'created' => '2014-09-22 21:45:38',
            'modified' => '2014-09-22 21:45:38'
        )
    )
)

我做错了什么?我已经在循环中拥有$email = new CakeEmail();,我已经在循环结束时尝试了unset($email),我已经做了我能想到的一切。但是,它不会发送。

编辑1

如果我调试发送结果,结果如下。我选择了两封电子邮件。

/app/Controller/InvitesController.php (line 137)
array(
    'headers' => 'From: "Invite" <invites@example.co.za>
Reply-To: replytoaddress@gmail.com
X-Mailer: CakePHP Email
Date: Tue, 23 Sep 2014 07:46:43 +0200
Message-ID: <54210943231844fc81b3020cc69187ab@localhost>
MIME-Version: 1.0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit',
    'message' => '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
    <title>Emails/html</title>
</head>
<body>
    <div width="100%" style="text-align:center">
        <table width="300px">
    <tr>
        <td>
            <p style="font-size: 8px; color:#222222;">
                If this email does not display correctly, please click the yellow banner and allow images from this domain. Otherwise, click this link.
            </p>
        </td>
    </tr>
    <tr>
        <td>
            <img src="http://localhost/marike/img/email/tent.jpg" alt="" /><br><a href="http://localhost/marike/pages/home?i=13&amp;k=207ac02e711ec6c09c0e86e7af676e18d7f14308"><img src="http://localhost/marike/img/email/link.jpg" alt="" /></a>        </td>
    </tr>
</table>    </div>
</body>
</html>
'
)
/app/Controller/InvitesController.php (line 137)
array(
    'headers' => 'From: "Invite" <invites@example.co.za>
Reply-To: replytoaddress@gmail.com
X-Mailer: CakePHP Email
Date: Tue, 23 Sep 2014 07:46:43 +0200
Message-ID: <54210943c83c432b85e3020cc69187ab@localhost>
MIME-Version: 1.0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit',
    'message' => '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
    <title>Emails/html</title>
</head>
<body>
    <div width="100%" style="text-align:center">
        <table width="300px">
    <tr>
        <td>
            <p style="font-size: 8px; color:#222222;">
                If this email does not display correctly, please click the yellow banner and allow images from this domain. Otherwise, click this link.
            </p>
        </td>
    </tr>
    <tr>
        <td>
            <img src="http://localhost/marike/img/email/tent.jpg" alt="" /><br><a href="http://localhost/marike/pages/home?i=14&amp;k=03fd8bdb6d91f2a30963034ff9e56317e3894eeb"><img src="http://localhost/marike/img/email/link.jpg" alt="" /></a>        </td>
    </tr>
</table>    </div>
</body>
</html>
'
)

0 个答案:

没有答案