php - CakeEmail loop not sending -
i have app sends email using cakeemail. works 100% fine if send 1 email , can view email in inbox , looks should.
now, when put same send bit in loop, , loop through array unique keys , try send it, doesn't deliver 1 email.
here function:
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 $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")); }
as stated, if pass 1 array such sends:
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' ) )
however more 1 below , fails no error.
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' ) ) )
what doing wrong? i've had $email = new cakeemail();
inside loop, i've tried unset($email)
@ end of loop, i've done think of. however, doesn't send.
edit 1
here result if debug send result. i've selected 2 emails.
/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 email not display correctly, please click yellow banner , allow images domain. otherwise, click 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&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 email not display correctly, please click yellow banner , allow images domain. otherwise, click 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&k=03fd8bdb6d91f2a30963034ff9e56317e3894eeb"><img src="http://localhost/marike/img/email/link.jpg" alt="" /></a> </td> </tr> </table> </div> </body> </html> ' )
Comments
Post a Comment