For one of my current projects I’m going to be writing a custom email class that will both send and receive email from an external/internal mail server. In order to make the module ultra-portable I’m going to be using an SMTP connection to take care of both tasks.
Right now I’m tutoring on the very excellent PHPMailer program that I’ve used many a time. It’s a very good module that has real good support backing it with frequent updates and bug patching via codeworxtech. The module I plan on building is going to be full PHP5, unlike PHPMailer which is written for PHP4. Ok so now we’ve got some background, let’s get to the code.
First thing we’ll need to load the file up and instantiate the class:
include('class.smtp.php');
$smtp = new SMTP();
Next we have to connect to the smtp server:
$smtp->Connect('mail.yourserver.com');
Finally we will authorize our smtp user via the Authenticate function:
$smtp->Authenticate('username', 'password');
Now, if we query the module for a connection status it should return true ( == 1 ).
So that’s all it takes to establish and log into an SMTP server via class.smtp.php. The module makes really good use of the fsockopen() function within PHP and I plan on taking a similar approach to my SMTP module.
Download class.smtp.php here.
Posted on June 26, 2008 at 10:21 pm
Came upon this rather slick geocode class written in PHP5 for use with google maps.
Thought I would share it.
Posted on June 21, 2008 at 9:51 pm
Just fixed the weird spacing on the p tag within posts, and commentlist list-style-position to outside.
Should help clean things up a bit.
Posted on at 8:56 pm
if($blog->lastUpdate > '2 months') {
echo 'DUDE WTF';
else {
echo 'n_n';
}
Posted on June 20, 2008 at 10:47 pm
Be sure to grab this package, if you’re doing any major PHP development on your Ubuntu box.
Running PHP interactively is a fun and productive way to debug and test out your applications code without having to refresh your browser every time you make a change.
Besides having to install the package, you have to add the -a flag to /usr/bin/php under the terminal.
It’s that simple. You can use absolute paths when including files, or cd into your applications directory and begin relatively including your code base.
While you could technically run your entire application under the interactive console, I would highly discern anyone from doing so. I recommend you just include the current file you are testing and work out any bugs one at a time.
I know a lot of developers are using and writing their own test modules to debug their code for them, but I prefer to be face-to-face with my code when I’m testing. You start to build a familiarity with your code in doing so and finding better ways to do things when you’re dealing with it personally. After all you’re going to be the one documenting and interfacing with the code, be one with the code.
Posted on at 10:33 pm