Log in

View Full Version : PHP Attachment Email



SChaput
07-07-2010, 05:30 PM
Hello All,

I"m trying to attach a .pdf file to a php mail() command, and having alot of difficulties. Here is my code:


move_uploaded_file($_SESSION['tempinfo'], $_SESSION['target_path']);

$file = fopen($_SESSION['target_path'], 'rb');
$data = file_get_contents($_SESSION['target_path'], filesize($_SESSION['target_path']));
$attachment = chunk_split(base64_encode(file_get_contents($_SESSION['target_path'])));

$random_hash = md5(date('r', time()));
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";


$message .= "--PHP-alt-<?php echo $random_hash; ?>--

--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: application/pdf; name='Something.pdf'
Content-Transfer-Encoding: base64
Content-Disposition: attachment

<?php echo $attachment; ?>
--PHP-mixed-<?php echo $random_hash; ?>--
";


The beginning of the code is where the file is uploaded, and when the email reaches its final destination it comes through as a bunch of gibberish. Any ideas?

Thanks