This walkthrough will assist in sending emails through phpMailer and is intended for webmasters who are familiar with php.

First, download phpMailer using our direct download link here:

PHPMailer Direct Download

Unzip the archive and upload the resulting 'phpmailer' folder into your public_html folder.

In this example, we will be referring to a basic form such as the following. Notice that the action is set to email.php

Our email.php script, which will process the form data and send the email, will need to include the class.phpmailer.php file:

Note that the require path should reflect the location of the phpmailer.php file.  Now, your actual mailing script in this case would end up looking like my example below:

Here is more detail on much of the code above:

$mail->IsSMTP();
This tells the script that the method of sending is SMTP

$mail->Host = "localhost";
This is the hostname of the mail server being used.  If you are sending from our server, this can be localhost or mail.yourdomain.com

$mail->From = " This email address is being protected from spambots. You need JavaScript enabled to view it. ";
The email address that the mail will appear to be from.  This does not have to match your SMTP username, but must be a valid email address.

$mail->FromName  =  "Your Name";
The name that will appear as the sender of the email

$mail->AddAddress(" This email address is being protected from spambots. You need JavaScript enabled to view it. ");
Who will be receiving the form results.  You can add as many recipients as you want simply by duplicating this line in the script.

$mail->SMTPAuth = "true";
This tells the script to use SMTP authentication, which is required to send mail through our servers.

$mail->Username = "your@emailaddress";
These are your login credentials for SMTP, which should reflect a valid email username and password.  If this is an account you set up from your cPanel, your username will be your entire email address.

$mail->Subject = "Feedback form results";
This is the subject line of the email that will be sent.

$mail->Body = $message;
For the message body, you will need to rename $message with the variable that you created in your HTML form for the message field.

$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;

Now when you send an email using the form, the form will use SMTP the same as an email client would. For a listing of the optional variables that you can add, you should read the documentation: http://phpmailer.sourceforge.net/docs/

Did you find this article helpful?
jay 2012-06-22 1:28 pm
It's a very good explanation for a novice like me who was gropping for the right direction. Thanks for posting

Login to comment.

Your Opinion Matters

... but we need to know what you're thinking!

The Community Support team wrote the article you're looking at now. We like to think it's perfect, but we're sure you have some suggestions. Please, let us know what they are!

Feedback
Your Email Address
Because we'd like to talk with you!

Support Center Search

Current Customers

Email: support@WebHostingHub.com Ticket: Submit a Support Ticket
Call: 877-595-4HUB (4482)
757-416-6627 (Intl.)
Chat: Click To Chat Now

Ask the Community

Get help with your questions from our community of like-minded hosting users and Web Hosting Hub Staff.

Not a Customer?

Get web hosting from a company that is here to help.