I have an application I am developing where the user is allowed to email the article he/she is viewing. I am using Ajax to process this. Basically the user adds his/her email/name and the email of person the message is supposed to be sent to. I am having a problem passing an array of data to my cakephp function. The data is being placed in the array accurately, but I cannot see it in my CakePHP function specifically the email that is being sent.
My Javascript Code
var dataString = new Array();
dataString[0] = name;
dataString[1] = email;
// This will display Joe Schmoe, email@domain.com
alert(dataString); return false;
$('#contact-area').html("<div id='Sending' style='margin-left:410px;color:red;border:1px solid red'>Enviando...Por favor, aguarde um momento!</div>");
$.ajax({
type: "POST",
url: "/articles/enviar",
data: dataString,
success: function() {
$('#Sending').hide();
$('#contact-area').html("<div id='message' style='margin-left:410px;color:red;border:1px solid red'></div>");
$('#message').html("<h3>A Sua Mensagem Ja Foi Enviada!</h3>")
.append("<p>Obrigado.</p>")
.hide()
My Controller Action
function enviar(){
//debug($emailInfo);
// Send email with new password
$this->Email->to = 'xxxxxxx@yahoo.com';//testing without array
$this->Email->subject = 'Hello';//$emailInfo['name'].' - Noticia Na Bravanews';
$this->Email->from = 'xxxxxx@bravanews.com';//testing without array
$this->Email->sendAs = 'html';
$this->Email->template = 'enviar_email';
$this->Email->smtpOptions = array(
'port'=>'465',
'timeout'=>'30',
'host' => 'ssl://smtp.gmail.com',
'username'=>'xxxxx@gmail.com',
'password'=>'xxxxxxxx'
);
$this->Email->delivery = 'smtp';
// this displays as nothing
$this->set('emailInfo', $this->data);
if($this->Email->send()){
return true;
}else{
return false;
}
}
And my email template
Hello,<br />
<?php e($emailInfo[0]); ?> sugeriu que leias a seguinte notícia na Bravanews.<br>
<?php e($emailInfo[1]); ?><br>
Por favor clique no link abaixo:<br /><br>
<?php debug($emailInfo); ?>
How do I go about fixing this issue. I cannot transpose anything to the email template so I can print or email…
You must send variables in an array named data so that you can find them in $this->data.
Else in CakePHP 1.3 you can not pass parameters to the view by using the $this->set(). For me I create my own component based on the Email CakePHP component to give the possibility to pass parameters to the view.