Joob Posted October 10, 2017 Share Posted October 10, 2017 Hello, I have a problem with my code.. I cant do download attachment, when I click on link "image.jpg", the link appears this way "www.site.com/image.jpg" but the link doesnt existe. $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("/Content-Type: multipart\/alternative; boundary=\"(.*?)\"/", $email_body, $getKey); //$op_getKey = preg_match_all("/alternative; boundary=\"(.*)\"/", $email_body, $getKey); $op_getKey = preg_match_all("/boundary=\"(.*)\"/", $email_body, $getKey); //$has_attachment = preg_match_all("/multipart\/mixed/; boundary=\"(.*?)\"/", $email_body, $attachment); $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 .. Regards Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.