Format for sending attachment via email

2 posts by 2 authors in: Forums > CMS Builder
Last Post: August 6, 2019   (RSS)

By daniel - August 6, 2019

Hi nmsinc,

The basic format for adding an attachment is:

  $mailArray1 = array( 
    'to'      => $_REQUEST['email_to'],
    'from'    => $_REQUEST['email_from'],
    'subject' => $_REQUEST['subject'],
    'html'    => $_REQUEST['content'],
    'attachments' => array(
      'filename' => $fileData,
    ),
  ); 

The exact usage will depend on what type of file you're attaching, and where it comes from. If you are adding an attachment from a submitted form, you should be able to use something like this:

  $mailArray1 = array( 
    'to'      => $_REQUEST['email_to'],
    'from'    => $_REQUEST['email_from'],
    'subject' => $_REQUEST['subject'],
    'html'    => $_REQUEST['content'],
    'attachments' => array(
      $_FILES['file_upload']['name'] => file_get_contents($_FILES['file_upload']['tmp_name']),
    ),
  ); 

You will need to change "file_upload" to match the name of your file input.

Let me know if this works for you, or if you have any issues.

Thanks!

Daniel
Technical Lead
interactivetools.com