Connecting to an SMTP server using class.smtp.php
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 ).
echo $smtp->Connected();
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.
josh approves this message.
Comment by josh — August 2, 2008 @ 1:57 pm
where in wordpress would I put this file?
Comment by Max — August 3, 2008 @ 1:39 am