I'm trying to use PHP to send an email with an attached file. I've followed the excellent tutorial at http://webcheatsheet.com/PHP/send_email_text_html_attachment.php#attachment and made the following changes:
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: application/txt; name="<?php echo $_POST[log_file]?>"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
Neither the original script or my amended script seems to attach any files to my emails. Anyone have any idea what I'm doing wrong.
Note: the files I'm attaching to my form are all text files (various file extensions e.g. .log, .txt etc).
OK, I've now proven I think that the MIME encoding part of this script isnt working. I've placed a text file in my upload directory and changed the script to read:
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: text/plain; name="<?php echo $_SERVER['DOCUMENT_ROOT']. '/upload/test.txt' ?>"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
When looking at the email source on receipt I see the full path and document name under Content-Type: text/plain; name=, but theres no attachment, encoded or otherwise.
Anyone know how I get this to work?
I've tried the following:
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: text/plain; name="<?php echo $_FILES['file']['name']; ?>"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
This presents the file name in the email source, but no attachment, interestingly:
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: text/plain; name="<?php echo $_FILES['file']['temp_name']; ?>"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
Returns an empty file name and still not attachement, I can only assume the temp file has bee deleted by the time I execute this?
Attach Log File:
isn't storing the file anywhere so the mail script cant find it so encode. Anyone know how I define a default location in PHP for the form to store the files? – Taffman Jul 24 '13 at 10:05