Using cfmail() (ACF2018), how does one go about adding in parameters?

96 Views Asked by At

I have a function that sends e-mail which works fine in it's basic form. However I need to add in params for images and attachments and can't find any documentation other than the basic cfmail() functionality.

cfmail(
  to = arguments.emailTo, 
  from = arguments.emailFrom, 
  subject = arguments.emailSubject, 
  type = 'html'
) { 
  writeOutput(arguments.mailbody);
}

I feel they should be up above the mailbody but can't find any docs on how to add them.

1

There are 1 best solutions below

0
Steve On

The linked documents above are great for new mail(), but - at least what I saw - were not updated for the newer cfmail() function. Here's the solution that also includes a boolean if one image is optional. I also found that in the included e-mail body, CID: does not show the image in Outlook (but is fine in Gmail), but cid: works in both.

  private void function sendEmail (
    required string mailbody,
    required string emailTo,
    string emailFrom = 'this is a subject line',
    required string emailSubject,
    boolean includeBoth = false
  ) output = false {
  cfmail(
    to = arguments.emailTo, 
    from = arguments.emailFrom, 
    subject = arguments.emailSubject, 
    type = 'html')
      {
        cfmailparam(file='C:\path\to\my\image\image.jpg', contentid='header', disposition='inline');
        if (arguments.includeBoth) {
          cfmailparam(file='C:\path\to\a\different\image\icon.png', contentid='icon', disposition='inline');
        }  
        writeOutput(arguments.mailbody);
      }