Hello,
I have a problem with my code.. I cant do download attachments, when I click in attachment "image.jpg", the link appears this way "www.site.com/image.jpg" but the link doesn't existed, and go to automatically to my home page without download the file..
$id = $_POST['id'];
$pdo = new PDO("sqlite:mydb.db");
$email = $pdo->query("SELECT * FROM `myemails` WHERE `id`='$myid'")->fetch(PDO::FETCH_ASSOC);
$email_body = base64_decode($email['message']);
$letter_html = "";
$op_getKey = preg_match_all("/boundary=\"(.*)\"/", $email_body, $getKey);
$has_attachment = preg_match_all("/multipart\/mixed/", $email_body, $attachment);
if ($op_getKey) {
if ($has_attachment) {
$mailParts = explode("--" . $getKey[1][1], $email_body);
$attachParts = explode("--" . $getKey[1][0], $email_body);
$get_attach_name=preg_match_all("/filename=\"(.*?)\"/", $attachParts[2], $attach_name);
$get_attach_type=preg_match_all("/Content-Type: (.*?);/", $attachParts[2], $attach_type);
$pure_code = explode("\n\n",$attachParts[2]);
$pure_code = str_replace("\r","",$pure_code[1]);
$pure_code = str_replace("\n","",$pure_code);
}else{
$mailParts = explode("--" . $getKey[1][0], $email_body);
}
Can you give me some help implementing this code in my code?
$savedir = __DIR__ . '/attachment/';
$myemail = $email->search('ALL');
if ($myemail ) {
rsort($myemail );
foreach ($myemail as $my2email) {
foreach ($my2email->getAttachments() as $attachment) {
$savepath = $savedir . $attachment->getFilename();
file_put_contents($savepath, $attachment);
}
}
}
So that it is possible, whenever you receive an email, that the file go to the "attachment" folder and can download the image or file ..
When I click in attachment and I just wanted that's possible to download the image, pdf, txt, zip, rar, etc.. once they are saved in the attachment folder.
I already called the attachment of these two forms, but nothing..
PHP Code:
<a target="_blank" href="https://site.com/<?=$attach_name[1][0]?>" data-target="<?=$id?>"><?=$attach_name[1][0]?></a>
<a target="_blank" href="data:<?=$attach_type[1][0]?>;base64,<?=$pure_code?>"> <?=$attach_name[1][0]?> </a>
I don't know if u understand my problem.
Best Regards