android6011 Posted June 16, 2008 Share Posted June 16, 2008 I am at the point where I am able to open my imap inbox, but how can I look for an email with a certain subject line and if it has it, save the attachment? Quote Link to comment https://forums.phpfreaks.com/topic/110351-use-php-to-check-email-inbox-for-certain-subject-then-save-attatchment/ Share on other sites More sharing options...
ohdang888 Posted June 16, 2008 Share Posted June 16, 2008 in my opinion, you should just have whoever is sending you the attachment to use a form on your site. Quote Link to comment https://forums.phpfreaks.com/topic/110351-use-php-to-check-email-inbox-for-certain-subject-then-save-attatchment/#findComment-566195 Share on other sites More sharing options...
android6011 Posted June 16, 2008 Author Share Posted June 16, 2008 because im using my phone to send text/picture messages to my email inbox. just trust me, my convoluted methods are the best way for me to get my desired results lol Quote Link to comment https://forums.phpfreaks.com/topic/110351-use-php-to-check-email-inbox-for-certain-subject-then-save-attatchment/#findComment-566199 Share on other sites More sharing options...
bluejay002 Posted June 16, 2008 Share Posted June 16, 2008 so you want to download the attachement after matching subjects right? try this: <?php $mbox = imap_open($mail_server, $mail_box, $password); $count = imap_num_msg($mbox); for($index = 0; $index < $count; $index++) { $obj = imap_headerinfo($mbox, $index); $string_to_find = 'look for text here'; // change the if for the search algo you want if($string_to_find == imap_utf8($obj->subject)) { // put your code here to dl the attachments } } imap_close($mbox); ?> when dl the attachments... you need to be aware of the encodings and the different ways attaching files. it seems that different mail clients uses different ways of attaching of files. just check the rest of the imap functions: http://php.net/imap Quote Link to comment https://forums.phpfreaks.com/topic/110351-use-php-to-check-email-inbox-for-certain-subject-then-save-attatchment/#findComment-566220 Share on other sites More sharing options...
android6011 Posted June 16, 2008 Author Share Posted June 16, 2008 Thanks That really helped fix what mess I had, but its actually downloading the attachment I'm really having problems with, like how can i put the file as a variable to work with and save it to a directory? Quote Link to comment https://forums.phpfreaks.com/topic/110351-use-php-to-check-email-inbox-for-certain-subject-then-save-attatchment/#findComment-566262 Share on other sites More sharing options...
bluejay002 Posted June 16, 2008 Share Posted June 16, 2008 ill just give you the idea how it is: first, you need to check the structure of the mail. from here you will know which part of the message is the attachment. second, get the attachement (you may do this repeatedly since there could be multiple attachments). third, determine the type of attachment you are dealing with. fourth, use the proper encoding before saving. fifth, save the file based on the name of the file. Quote Link to comment https://forums.phpfreaks.com/topic/110351-use-php-to-check-email-inbox-for-certain-subject-then-save-attatchment/#findComment-566264 Share on other sites More sharing options...
android6011 Posted June 16, 2008 Author Share Posted June 16, 2008 i attached a file that displays imap_body and onyl imap_body printed [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/110351-use-php-to-check-email-inbox-for-certain-subject-then-save-attatchment/#findComment-566270 Share on other sites More sharing options...
android6011 Posted June 16, 2008 Author Share Posted June 16, 2008 any ideas anyone? Quote Link to comment https://forums.phpfreaks.com/topic/110351-use-php-to-check-email-inbox-for-certain-subject-then-save-attatchment/#findComment-566821 Share on other sites More sharing options...
bluejay002 Posted June 17, 2008 Share Posted June 17, 2008 you need imap_fetchstructure() to check to check if it is an attachment (and its encoding). if it is, you need imap_fetchbody() to get the attachment and to store it into a variable.. then write it in your server. there you go... i hope this is clearer now... i was thinking that you should do this yourself but i guess am bit generous this time . happy programming!!! God bless! cheers, Jay Quote Link to comment https://forums.phpfreaks.com/topic/110351-use-php-to-check-email-inbox-for-certain-subject-then-save-attatchment/#findComment-566920 Share on other sites More sharing options...
android6011 Posted June 17, 2008 Author Share Posted June 17, 2008 Thanks. I've tried a million things and I REALLY appreciate your help Quote Link to comment https://forums.phpfreaks.com/topic/110351-use-php-to-check-email-inbox-for-certain-subject-then-save-attatchment/#findComment-566948 Share on other sites More sharing options...
bluejay002 Posted June 17, 2008 Share Posted June 17, 2008 Thanks. I've tried a million things and I REALLY appreciate your help eheh . here is a more in-depth look: once you get imao_fetchstructure(), it returns a lot of info. what you need are: say you have, $info = imap_fetchstructure($mbox, $item); foreach($info->parts as $part) { // this checks if its an attachment if ($part->disposition == "attachment" || $part->disposition == "inline") { // get the filename $filename = $part->dparameters[0]->value; // retrieve the data here // using imap_fetchbody() } } so how was it? Quote Link to comment https://forums.phpfreaks.com/topic/110351-use-php-to-check-email-inbox-for-certain-subject-then-save-attatchment/#findComment-566972 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.