I’v been sitting on this for a couple of hours and searched through the forum with no success.
I’v done a basic mailer that gets addresses from a checkbox column and send them all some message.
I tried using ‘name’ or ‘value’ but the column is still sending the id instead of the email.
Here my code: (for debugging purpose I’v fixed the email address to mine , and the users’ addressed are going to the mail so that I’ll be able to see the change)
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'test-person-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array(
'class'=>'CCheckBoxColumn',
'selectableRows' =>2,
'value'=>'$data->email', //should render the email instead of the id
),
'id',
'name',
'email',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
<?php
echo CHtml::button("send",array("id"=>"sender"));
?>
<?php
Yii::app()->clientScript->registerScript('send','
$("#sender").click(function(){
var checked=$("#test-person-grid").yiiGridView("getChecked","test-person-grid_c0");
var count=checked.length;
if(count>0 && confirm(" do you want to send "+count+" message? "))
{
$.ajax({
data:{checked:checked}, //can this cause the problem ? ? ?
url:"'.CHtml::normalizeUrl(array('testPerson/sender')).'",
success:function(data){$("#test-person-grid").yiiGridView("update",{});},
});
}
});
');
?>
and the controller:
public function actionSender()
{
if(Yii::app()->request->getIsAjaxRequest())
{
$checkedMails=$_GET['checked'];
foreach($checkedMails as $message)
{
// $message = "This is a test mail from Mark Brass";
// In case any of our lines are larger than 70 characters, we should use wordwrap()
//$message = wordwrap($message, 70, "\r\n");
mail('mark2bra@gmail.com', 'Test mail', $message);
}
}
}
Now, the whole thing do work, but I get in my mail the users’ ids that I’v checked
Instead of ‘value’ I had tried ‘name’=>‘email’, but it didn’t work as well.
Cheers,
Mark.