GSTAR
(Omzy83)
November 29, 2010, 1:03am
1
I send an email through my controller and set the body content via a view file as follows:
$body=$this->renderPartial('//mail/newEnquiry', array('model'=>$model), true);
I have the following in my email view file:
<?php echo CHtml::link('View this Enquiry now', array('admin/enquiry/view', 'id'=>$model->id)); ?>
When the email is received on the client the hyperlink address is just ‘/admin/enquiry/view/id/32’
It needs to include the full URL (http://www.mysite.com/ …). I thought it would do this automatically but that does not seem to be the case…
trejder
(Tomasz)
November 29, 2010, 10:01am
2
This is because e-mails sent by PHP mail() function are plain-text encoded by default.
You have to provide extra (fourth) parameter to mail() function with proper headers definitions. I do this like this:
$subject = 'Day Report for '.date('l, jS F Y');
$message = 'message';
$headers =
'MIME-Version: 1.0'."\r\n".
'Content-type: text/html; charset=utf-8'."\r\n".
'From: "WAP Service" <wap-service@example.com>'."\r\n".
'Reply-To: wap-service@example.com'."\r\n" .
'X-Mailer: PHP/'.phpversion();
$result = mail($to, $subject, $message, $headers);
And it works fine for me. Not only links but all HTML tags are perfectly inserted into generated e-mail.
GSTAR
(Omzy83)
November 29, 2010, 11:07am
3
No, that isn’t the problem - I have already put in the HTML headers! The URL is generated but it’s ‘href’ attribute is just ‘/admin/enquiry/view/id/32’ !
jacmoe
(Jacob Moena)
November 29, 2010, 11:17am
4
You can do this in several ways.
Here’s one:
<?php echo CHtml::link('View this Enquiry now',
Yii::app()->createAbsoluteUrl('admin/enquiry/view', 'id'=>$model->id)); ?>
GSTAR
(Omzy83)
November 29, 2010, 11:35am
5
Thanks, this has worked. By the way the GET parameters need to be an array.