How to use HTML template as body to an Email?
Hello Fellow Dancers, I am trying to send an email as HTML using HTML template. Does anybody know that how can I use HTML template (that resides in view directory) as email body? So far I tried the following code but am not able to get it working. It may be not the right way of doing it. try { email { from => 'abc@xyz.com', to => 'xyz@abc.com', subject => 'test email', body => template 'contactUsEmail.tt', {name => $params->{'name'}, email => $params->email'}, message => $params->{'message'}}, type => 'html' }; } catch { error "Could not send email: $_"; }; Another possible solution that I am thinking of, I can just store the entire HTML code in a scalar variable and use it as email body (e.g. body => $template, where $tempalte contains the HTML code as $template ="html code.."). Thanks for the help. Best, Tushar Dave
Hey, I use the second solution. Best regards, Attila
On 26 Jan 2016, at 19:57, Tushar Dave <tushardave26@gmail.com> wrote:
Hello Fellow Dancers,
I am trying to send an email as HTML using HTML template. Does anybody know that how can I use HTML template (that resides in view directory) as email body? So far I tried the following code but am not able to get it working. It may be not the right way of doing it.
try { email { from => 'abc@xyz.com <mailto:abc@xyz.com>', to => 'xyz@abc.com <mailto:xyz@abc.com>', subject => 'test email', body => template 'contactUsEmail.tt', {name => $params->{'name'}, email => $params->email'}, message => $params->{'message'}}, type => 'html' }; } catch { error "Could not send email: $_"; };
Another possible solution that I am thinking of, I can just store the entire HTML code in a scalar variable and use it as email body (e.g. body => $template, where $tempalte contains the HTML code as $template ="html code..").
Thanks for the help.
Best, Tushar Dave
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
On Tue, 2016-01-26 at 13:57 -0500, Tushar Dave wrote:
try { email { from => 'abc@xyz.com', to => 'xyz@abc.com', subject => 'test email', body => template 'contactUsEmail.tt', {name => $params->{'name'},
^^^^ Only guessing, but I suspect you're going to have problems with precedence here. Try adding some brackets. E.g. body => template('contact..', {...} )
On Tue, Jan 26, 2016 at 8:57 PM, Tushar Dave <tushardave26@gmail.com> wrote:
Hello Fellow Dancers,
I am trying to send an email as HTML using HTML template. Does anybody know that how can I use HTML template (that resides in view directory) as email body? So far I tried the following code but am not able to get it working. It may be not the right way of doing it.
try { email { from => 'abc@xyz.com', to => 'xyz@abc.com', subject => 'test email', body => template 'contactUsEmail.tt', {name => $params->{'name'}, email => $params->email'}, message => $params->{'message'}}, type => 'html' }; } catch { error "Could not send email: $_"; }; [KB] You can use it as follow:
my $body = template 'contactUsEmail.tt', {name => $params->{'name'}, email => $params->email'}, message => $params->{'message'}}, { layout => undef }; try { email { from => 'abc@xyz.com', to => 'xyz@abc.com', subject => 'test email', body => $body, type => 'html' }; } catch { error "Could not send email: $_"; };
Another possible solution that I am thinking of, I can just store the entire HTML code in a scalar variable and use it as email body (e.g. body => $template, where $tempalte contains the HTML code as $template ="html code..").
Thanks for the help.
Best, Tushar Dave
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
-- Kadir Beyazlı Computer Engineer GSM : +90 535 821 50 00
participants (4)
-
Andrew Beverley -
Attila Bárdi -
Kadir Beyazlı -
Tushar Dave