nette / mail

A handy library for creating and sending emails in PHP
https://doc.nette.org/mailing
Other
469 stars 71 forks source link

How to properly include HTML email in setHTMLBody function? #56

Closed fluxxus closed 5 years ago

fluxxus commented 5 years ago

First let me tell you my needs with Nette mail.

I have a simple checkout done via Stripe. After successful charge is made, using Stripe webhooks for that event I need to send email with attachment.

For sending emails I looked at Mailgun and Sendgrid, but it seems they have issues with sending email to Outlook, I guess Outlook blocks their emails if not sent via dedicated IP.

Then I started looking for a simple PHP solution(since the charge is done via PHP) and found Nette mail. But I am having trouble adding HTML part to Nette mail.

In the examples you use your templating language, can it be done without it? Do I need to stringify my HTML code first?

p.s. I don't work with PHP, sorry if this is a stupid question :)

fluxxus commented 5 years ago

After some googling, this is what I did.

I've put the whole HTML email content inside a variable with HEREDOC syntax and used that for setting the mail body. From what I understand HEREDOC saves me from the hell of escaping quotes, among other things.

And it works :)

Is this ok what I just did? What is the prefered approach?

milo commented 5 years ago

Hi @Madebym

Nette Mailer does't care about HTML validity. If you are sure your HTML string is not malformed, you did it right. Just call setHtmlBody() with HTML string.

For further question, use Nette Forum please.