While GoDaddy is a great hosting server (reliable, flexible and secure from what I’ve experienced) they have always been a bit tight with what features are enabled on their servers. I can’t blame them - I’ve experienced two hacked shared servers (non-GoDaddy) in the past two years due to a security exploit that went unnoticed. The one issue I consistently have is sending email from a Web site, most commonly for a contact form. In this post I will go over configuring a module named PHPMailer in order to accomplish sending an e-mail from GoDaddy’s servers.PHP Who?
PHPMailer is an open-source component from CodeWorxTech that is one of the easiest pieces of code I’ve used in a long time. Configuration is short and simple and they provide plenty of documentation on using it. Just searching “PHPMailer” on Google is like an entire API resource due to it’s widespread use.
Setup
I won’t go over how to setup PHPMailer since there is enough out there to get you started. This post is more about configuring it to work with GoDaddy. If you want to know how to install it and include it in your project, look here: http://phpmailer.codeworxtech.com/tutorial.html#2.
GoDaddy’s Relay Host
While GoDaddy has disabled the mail() command for security reasons, they do allow you to connect to their SMTP relay server to send emails. In this configuration it is a very minimal modification as simple as specifying the correct host. Unfortunately it took me 5 hours to find this information before I knew it existed. Here is the code:
// This code assumes you have already include class.phpmailer.php in your project.
// Instantiate new PHPMailer
$mail = new PHPMailer();
// Configuration
$mail->Host = “relay-hosting.secureserver.net”; // GoDaddy’s relay server
$mail->From = “name@your-domain.com”;
$mail->FromName = “John Doe”;
$mail->Subject = “Sample Email From GoDaddy”;
$mail->Body = “Hello, World!”;
$mail->AddAddress(”recipient-email@their-domain.com”, “Recipient Name”);
if (!$mail->Send()) {
$err = “Oops, couldn’t send the email: ” . $mail->ErrorInfo;
} else {
// Email sent successfully
}
Pretty simple, huh? You don’t even need to send your email login information which is good if you are sharing the file with a lot of subcontractors and don’t want to give them access to your account information.