SimplePHPMailer

Simple PHP Mailer for those who don't know PHP

View project on GitHub

What is this?

SimplePHPMailer is a simple drop-in script that helps you send email messages from your contact form. You do not need to know PHP in order to use this - as all the configuration and instructions are right in the script. You'll then choose a page to redirect to after submission. Just need a simple, drop-in solution? This is your script.

What happens?

Basically, it's very simple and dynamic. First, place the spmailer.php file in your project and configure. Second, create a form with any number of inputs. Third, start getting emails with those fields!

How to get started

The first step is to download the spmailer.php file and put it in your project. Click the link on the right to download your chosen type. If you're not sure which one you want, you probably want the .zip file. Next, place the php file in your project in the folder by your contact form html. Finally, open the file with the same tool you've been using to edit your HTML. You'll see configuration options that you can change here. These options should be pretty self-explanatory - but never fear! Below, you'll find more instructions.

Configuration Options

For this script, you basically have to make three decisions: What is the from email address, what email address should responses be sent to, and what page should be loaded after the page is successful. This configuration is done in the top part of the script.

How to edit PHP Code

You can use your favorite text editor to edit the PHP code. This might be the same tool you create HTML in. Then, when asked to change a particular value, enter the new value between the double quotes.

For example, if the value is "my@address.com" and you want to change it to your email address, you should change it to look like this "me@myaddress.com" - do not remove the quotes, add additional quotes or change any other part of the line. If you end up receiving some sort of error that seems like it's from PHP that is in bold and begins with T_, chances are there is a missing or extra quote.

To Email

Find the section towards the top of the script that says "To" email address. You'll see this line:

define('AaronSaray\SimplePHPMailer\TO_EMAIL', "to@address.com");

You need to change this so that it has your email address in there. So, for example, let's say you're email is john@smith.com, that line should now say:

define('AaronSaray\SimplePHPMailer\TO_EMAIL', "john@smith.com");

From Email

Following the same pattern of updating the PHP code as was done with the "to" address, change the "from" address. This is who the email from the website will look like it's from.

Subject Line

This is the subject line that your email will have. It is fine to leave it as it is. However, you may want to add the name of the site in the message instead. For example:

define('AaronSaray\SimplePHPMailer\SUBJECT', "Form submitted from aarons-cool-site.com");

Success URL

When the form has been successfully submitted and the email has been sent, this is the URL that the visitor will be sent to. You should probably point it to a success page on your website with a thank you message. Let the visitor know that their email has been sent.

What HTML is Required

Simply make an HTML form, using the method of post, with the action pointed to the spmailer.php file. If you have placed the spmailer.php file in the same directory or folder as your contact form's HTML page, this will be easy.

For example, imagine you have the following folder structure:

mysite.com/
 |
 -- index.html
 -- contact.html
 -- spmailer.php

Then, your form inside of contact.html will look like this:

<form method="POST" action="spmailer.php">
    <div><label>Name: <input type="text" name="full_name" required></label></div>
    <div><label>Email: <input type="email" name="email" required></label></div>
    <div><label>Message:<br><textarea name="message" required></label></div>
    <input type="submit" value="Send">
</form>

Now, any named HTML elements inside of this form will be sent to the spmailer.php script and sent directly to the recipient address in the script. Yay!

Errors and Validation

The script does some error checking and validation to make sure messages contain valid information. You should also program client-side validation for your required and specific fields as well. If you require a more robust form of error checking, this script may not be for you.