Email template not using themed version

瘦欲@ 提交于 2020-01-05 10:13:15

问题


I am using CakePHP 1.3 and the built in email features as described in the documentation. I have the html version of the template located in app/views/elements/email/html/reservation.ctp and its working as expected.

$this->Email->template = 'reservation'; // no '.ctp'

I also have a theme setup and most of the themed files are correctly overriding the default files. My problem is the themed email template is not being used when called from the themed site, its still using the email template file in the default path.

The default is at: app/views/elements/email/html/reservation.ctp

The theme is at: app/views/themed/myTheme/elements/email/html/reservation.ctp

Should the email template assignment automatically work with themes without the need for hard coding a path or is there another solution? Anyone else have this issue?


回答1:


in cakephp when you want to create email template. Lets suppose we want to create an Html email. and email config is configured.

Views[File Structure]:

1) your content email with variables should be located in View/Emails/html [reservation.ctp]
2) your template should be located in View/Layouts/Emails/html [default.ctp OR any new template you have made]

controllers:

Note: some people think when you write an action(in controller) you have to write a view for it. In this case (for sending email) is completely wrong. only if you want to show the result which email sent successfully or not then is fine.

lets say ReserveController ;) and sendReservationEmail

function sendReservationEmail( $to, $from,$subject ,$template, $variables=array()){

        $Email = new CakeEmail();
        $Email->config('smtp')
            ->viewVars($variables) 
            ->emailFormat('html')
            ->template($template['page'], $template['layout'])  //'reservation', 'default'
            ->from($from)                                      //'me@example.com' => 'My Site'    
            ->to($to)                                          //'you@example.com'
            ->subject($subject) //'Resevation'
            ->send();       
    }

Views (View/Emails/html/reservation.ctp):

Dear $this->viewVars['name'];

Welcome to our restaurant .....


来源:https://stackoverflow.com/questions/16572893/email-template-not-using-themed-version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!