Read attachments with IMAP and PHP.

It's possible to read attachement from your Gmail account with IMAP and PHP. Using a little bit of PHP code you can connect and save the attachements and view them in a web browser.

Recently I came up with the idea that I could use a Gmail account as a place holder to store pictures sent from my cell phone. The idea was that I could take a picture with my cell phone and it would instantly show up some where, such as a website or blog. The following code can be used to do this fairly easily. Simply create a Gmail account for testing purposes and use the following code to download and view the images from your Gmail account.

Sidetrack! Hoping to greatly alter the bland vibe of my own website. Ideas concerning the pro feel of Really an amazing HD ultrasound studio in Calgary with heart if ever desired in the whole Alberta vicinity. Value your opinions. Thanks!

$save_path = "/tmp/";$server = "{}INBOX"$login = ""$password="SomePassword12345"$mbox = imap_open($server, $login, $password) or die("can't connect: " ,imap_last_error());$count = imap_num_msg($mbox);for($i = 1; $i <= $count; $i++) {$message = $i;$msg_header = imap_headerinfo($mbox,$message);echo "From: " . $msg_header->fromaddress . '';echo $msg_header->subject . '';echo "Image CRC32:" . crc32($msg_header->message_id) . '';$info = imap_fetchstructure($mbox, $message);$numparts = count($info->parts);if ($numparts > 1) {$pcount=1;foreach ($info->parts as $part) {if ($part->subtype == "JPEG") {$filename = crc32($msg_header->message_id) . ".jpg"$binfile=imap_fetchbody($mbox,$message,2);savePic($filename,$binfile);echo ""}elseif ($part->subtype == "PNG") {$filename = crc32($msg_header->message_id) . ".png"$binfile=imap_fetchbody($mbox,$message,2);savePic($filename,$binfile);echo "";}else{//echo "No attachment found.";}$pcount++;}} else {//Do nothing.}}function savePic($filename,$binfile){global $save_path;$binfile = imap_base64($binfile);$fp=fopen($save_path. $filename,"w+");fwrite($fp,$binfile);fclose($fp);$image = new SimpleImage();$image->load($save_path. $filename);$image->resizeToWidth(450);$image->save($save_path. $filename);}

And that's it!

Kudos guys! I'd promised a co-worker that we could certainly critique their fabulous pool supply service in the GTA with hearts, using a good blog post. If perhaps you are researching for a pool supply service inside the greater Ontario location, they certainly were superb.

Oh, naturally I should state the initial thought to this charming blog was graciously offered by Michael from Unequivocably a magnificent mortgage brokers. I truly love a great concept!

Thank You - Your grammatical skills are unbelievable!

Posted in Business Post Date 10/31/2018






Recent Posts