Archive for the ‘Code’ Category

Connecting to an IMAP Mailbox with PHP

Sunday, December 7th, 2008

There are a number of cool things that you can do after opening up an IMAP connection in PHP (monitoring bounce-back rates, processing incoming attachments, etc.) but before you do, you have get connected. Normally, this is a pretty straight-forward process, but sometimes different mail server settings can throw you a curveball. Here's a couple quick tips to help you get started:

  1. Open up a phpinfo() page and make sure that you have the IMAP extensions installed. If you don't, here are the instructions on how to get them.
  2. Copy our PHP IMAP Connection Tester onto your server and configure it with your account information.
  3. That's it. I told you that was easy!

A note: I ran into the following error today: "Certificate failure for mail.example.com: Server name does not match certificate." It took me a while to find the solution but finally came up with this -- add /novalidate-cert after the port number. So, for example, if you're using our tester, set $mail_port = 143/novalidate-cert; Hope that helps!

If you have any other tips, help the world out and share them below!

Image Upload Form, Cron Job Tester, & MySQL Table Copier

Sunday, November 30th, 2008

Over the weekend, I posted three new code snippets:

The Image Upload Form has everything you need to create a simple HTML form allowing users to upload their own JPEG images. After it verifies that the image is valid, it saves it and generates a thumbnail using the PHP GD library of image functions. The code is clean, so it's pretty easy to manipulate it to suit your needs (other file formats, different resizing, etc.)

The Cron Job Tester is the result of an epic battle I had with the server hosting one of my client's sites. I couldn't figure out why these cron jobs weren't running and so constructed this little tester to simply log an entry in a text file every minute. From there, I was eventually able to find out that the host's "Easy Cron" function was overwriting my crontab file. Arrrgh...

Finally, I posted the PHP code to Copy All the Rows in a MySQL Table to another, identical MySQL table. You can, of course, do this easily in phpMyAdmin, but I needed to have the function automated for this particular project. Hopefully you can get some use out of it too.


Copyright © 2010, Ink Plant. All rights reserved.