Format for sending attachment via email
2 posts by 2 authors in: Forums > CMS Builder
Last Post: August 6, 2019 (RSS)
By nmsinc - July 30, 2019 - edited: July 30, 2019
I have the following email array and I need to add an attachment and I'm not sure how!
if ( @$_REQUEST['save'] ) {
$mailArray1 = array(
'to' => $_REQUEST['email_to'],
'from' => $_REQUEST['email_from'],
'subject' => $_REQUEST['subject'],
'html' => $_REQUEST['content']
);
$mailErrors1 = sendMessage($mailArray1);
if ($mailErrors1) {die("Mail Error #1: $mailErrors1"); }
// show thanks
$errorsAndAlerts = "Thanks, Your email has been sent along with any attachment!<br/><br/>\n";
$showEmailForm = false;
} // end if submit
I also need to know how to code the $PLACEHOLDERS for the attachment during the pass through so that the attachment shows up in the email!:
$FROM = $PLACEHOLDERS['from'];
$TO = $SETTINGS['adminEmail'];
$SUBJECT = $PLACEHOLDERS['subject'];
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!
Technical Lead
interactivetools.com