How to send HTML mail using SMTP authentication on Drupal

Yesterday I was helping a colleague who needed to send HTML formatted mail from a Drupal 7 site. I did some quick research and found the Mail system and HTML mail modules. I enabled the modules and configured them and figured I was done.

My colleague came back to me and told me that now, not only was the mail not sending as HTML, it wasn't sending at all!

Some research brought me to Using HTML Mail together with SMTP Authentication Support -- excellent!

I followed the steps in the tutorial and after creating the HTML mail / SMTP auth class I received a PHP error stating that Drupal had failed to load the class.

When you use the Mail system module to create a new class, behind the scenes it actually creates a new PHP (.inc) file and stores it in your sites /mailsystem/filename.inc . Unfortunately the file directory for the site I'm working on is outside of the Drupal root, and not easily accessible to the class loader. Along with this, we use a git deployment workflow, and the files directory is not version controlled.

Solution

I first grabbed a copy of the auto-generated file from the server, and then deleted the copy on the server. Then I added that file to a custom module using the files[] directive in the module's .info file (this tells Drupal to load the class). Finally I had to remove the existing entry for the file from the registry table of the database, making sure to remove the correct file, and that I had the generating module "mailsystem" as a WHERE clause.

Now we have a mail system class that does HTML formatting and SMTP authenticated delivery working with the appropriate modules, and it's version controlled too.

See also: #1369736: Alternative locations for "created" Class files?

3 Comments

4. Talk to your insurance professional regarding shedding unneeded protection. There could be several add ons on your car insurance that you do not absolutely need. Examples are usually protection for the carrental plus roadside support in case of a car accident. Realize totally the insurance you want to get rid of out of your car insurance.

Dangers Associated with Your home based business

hello world

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <img> <h2> <h3> <h4> <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • To post pieces of code, surround them with <code>...</code> tags. For PHP code, you can use <?php ... ?>, which will also colour it based on syntax.