This is my html template
Dear ##name##(##email##),
Thank you for contacting us.
I want to replace ##name## and ##email## with the receiver's name and email of the person who gets it which will be provided in the array. How do I do it?
This is what I've got so far
$to_email = array('[email protected]', '[email protected]', '[email protected]');
$to_name = array('apple', 'ball', 'cat');
$Email = new CakeEmail();
$Email->from($from);
$Email->to($to_email );
$Email->subject($subject);
$Email->emailFormat('html');
$Email->viewVars(array('data' => $body));
$Email->template('bulk');
$Email->send();
You should start with creating template for your email, which will be including your current content (I use name
example_template.ctpin my samples below):Then you have to modify way of setting up your
viewVars()andtemplate():There is also required to change way of sending emails to loop over emails instead of sending all recipients in one field. So combine your input arrays into one, e.g.:
Then just foreach over your array and send mails: