I have an issue where the code below sends the attachment but the file has the correct name but the contents are just the uploads/name of file in it. Why is the code below doing that?
Thanks
$name_of_uploaded_file= basename($_FILES['uploaded_file']['name']);
$uploaddir = "uploads/";
move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $uploaddir.$_FILES['uploaded_file']['name']);
$separator = md5(time());
$eol = PHP_EOL;
$attachment = chunk_split(base64_encode($uploaddir.$name_of_uploaded_file));
$to = 'ccotrainingrequests@walgreens.com';
$subject = 'New Training Request Ticket #' . $ticketid;
$message = 'Ticket #' . $ticketid . ' Has Been Submitted';
$headers = "From: ".$to.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";
$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$body .= "This is a MIME encoded message.".$eol;
$body .= "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= $message.$eol;
$body .= "--".$separator.$eol;
$body .= "Content-Type: application/octet-stream; name=\"".$name_of_uploaded_file."\"".$eol;
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment".$eol.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";
mail($to, $subject, $body, $headers);
You are not reading the contents of your file on the $attachment… line of code, you are
chuck_splitting the name of the file. That’s why only the name is getting sent. You need to do something like anfread()of the file and thenchunk_splitthat.