Pieter van Bijnen points out the importance of sending email in HTML format and including inline images. Accordingly, Ive updated the code in my original post to demonstrate such an email.
Also, dont delay setting up your own email domain. The code in my original post sends an email from the Mailgun sandbox domain. But all your test, development, and production code should send email from your own domain. Domain setup consists of two simple steps. First, generate DNS zone file TXT, CNAME, and MX records: login to Mailgun (or whichever email delivery service youve chosen), follow the link to add a new domain, and enter a subdomain name. Second, enter these records into the DNS zone file for your domain: login to your domain hosting account and follow the appropriate links to add zone file records. Other than entering these records, subdomain setup does not involve any other actions on the domain hosting account. If youre building applications that do both bulk marketing and transactional email, then keep their email reputations separate by setting up different email domains for each.