Jump to content

From template to email the right way.


Manol
 Share

Recommended Posts

Hello.

    I'm developing a cooking recipes website, people subscribe to it to get daily recipes.

    What would be the best way to send emails to them using fields and images from a template and most important that those email can be opened from a mobile device and most email clients and see it correctly.

 

Thanks.

Link to comment
Share on other sites

To send emails from the template you would use WireMail, accessible in the API through $mail

To get values for your image and other fields, just use regular $page->image, $page->title etc.

The hardest part will be the cross-client responsive Email template. This is not a trivial thing to do.  Some resources:
http://leemunroe.github.io/responsive-html-email-template/email.html
http://tedgoas.github.io/Cerberus/

If you send emails from ProcessWire and want to send them in plain text and in HTML, you typically construct the HTML email first and then convert that to a plain text version with something like

$emailMessageAdminHtml = "<h1>Some HTML</h1><p>with paragraph</p>";
$emailMessage = str_replace( "<br>", "\n", strip_tags($emailMessageAdminHtml, '<br>') );

// construct email
$mail->to($recipient);
$mail->from($sender);
$mail->subject($subject); 
$mail->body($emailMessage);
$mail->bodyHTML('<html><body>' . $emailMessageAdminHtml . '</body></html>');

// send
$mail->send();

 

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...