VulgarisOverIP

Send Email With PHP and GMail Hosted for Your Domain

I’ve been using Linux ever since I became a CS major at Georgia Tech five years ago. I’ve compiled my own kernels, maintained Apache and MySQL, and written custom IPTable’s; I’ve even setup printing AND scanning with modern hardware. But not once have I ever come close to setting up a working mail server.

On second though, I think I may have come close once. I sent out an email to myself and then sat there at my GMail inbox hitting refresh, waiting to receive the message. About five minutes later I found it in the spam folder and started reading about reverse IP pointers and DomainKeys. My brain started to hurt and in the end, I was sending messages through godaddy.com’s email servers and hoping most of my customers got their emails.

Now that GMail for your domain has arrived (if you’re a lucky beta winner, that is) it’s like hiring a world-class email server engineer and paying them nothing. It takes a little work because of GMail’s security requirements, but you end up with a rock solid email server that won’t send messages straight into spam folders.

First, download the standard PHPMailer libraries (version 1.73). The only thing you have to modify is the class.smtp.php file. Open it and go down to about line 683, in the Quit() member function. Comment out everything between the fputs() that sends the “quit” command and the if statement surrounding $this->Close() except for $rval = true;. The reason this works is unknown to me, but every time I tried to read from the socket after sending the “quit” command I got a lot of garbage.

Now just use the following settings:

$mail->From = '***@&&&.com';
$mail->Mailer = 'smtp';
$mail->Host = 'ssl://smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = '***@&&&.com';
$mail->Password = '***';

Replace the *’s and &’s for real values and you’re all set.

Comments