I have had problem with the code below. I don't know what might be wrong, but I hope you figure this out or a simple way I can send email with attachment... When I sent a try message, it sends something like this in the headers of the message...
--244f3f04128cb4e6797d0019662a1aaa Content-Type: application/octet-stream; name="phpStorm.txt" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="phpStorm.txt" QW1iZXIgVG93bnNlbmQNCg0KNTQzMDQ1LTE4MDIyMDEzDQowMDAwMXh3Smg1blJxU0hVTEVkVFpR TmZIRWF6SXUNCmc2bTRnTE1QOTZOMlFPVnpWckphZ0Y1cmpzZm9zTQ0KMmk0ZkFDQnVZV2MzMDlO cCFXb05kRW1EcnpWcVBi
CODE BELOW:
<?php
//file attachment
$strSid = md5(uniqid(time()));
if($_FILES["fileAttach"]["name"] != ""){
$strFilesName = $_FILES["fileAttach"]["name"];
$strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"] ["tmp_name"])));
$headers .= "--".$strSid."\n";
$headers .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";
$headers .= "Content-Transfer-Encoding: base64\n";
$headers .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
$headers .= "Content-Type: multipart/mixed; ";
$headers .= $strContent."\n\n";
if(mail($to, $subject, $message, $headers)){
echo "<div class=\"message_success\">Your message has successfully been sent</div>";//echo 'Your message has successfully been sent';
} else {
echo "<div class=\"message_error\">Message failed to sent, try again</div>";
}
}
?>