One of the easiest ways to build a loyal following for your website is to give your site visitors a quick and convenient way to get in touch with you. And while simply listing your email address on a contact page will get the job done, the experience will not be very seamless. Not to mention that the email address which you publish will be scraped by bots and you will find yourself on countless SPAM mailing lists.
A better solution is to integrate a contact form into your website. A contact form has two major advantages over giving your visitors your email address. On one hand, filling out a contact form is quicker and more convenient than opening a mail program and composing a message there. And on the other hand, you never share your email address publicly, thus protecting your own privacy. In this tutorial, we will show you how you can create a simple contact form using PHPMailer.
What Is the Difference Between PHPMailer and the PHP Mail() Function?
If you have spent any time researching how to create a PHP mailer script online, chances are that you have come across the terms PHPMailer and PHP Mail() function. These two terms sound remarkably similar, but in reality, they refer to different pieces of technology.
The PHP Mail() function is a part of the vanilla PHP installation and is available for use right out of the box. It is fully capable of powering a simple PHP mail script for a contact form. If you are interested in using the PHP Mail() function, you should check our article on how to create a working PHP Mail() script for a contact form. We also have an article which explains how to create a general-purpose mailing script that is powered by the PHP Mail() function.
PHPMailer, on the other hand, is a third-party library written in PHP, which makes the sending of email messages much easier. Moreover, it allows advanced functionality that is not found in the stock PHP Mail() function, such as the sending of attachments and using HTML/CSS to add custom formatting to your messages.
In this guide, we will focus on PHPMailer as the technology that will power our free email form script. More specifically, we will use the latest version of PHPMailer which at the time of writing is PHPMailer version 6.0.7. We will also provide a free download link for our PHP email contact form example.
What Are the Requirements for a PHPMailer Form to Send Email Messages Successfully?
We wish all of our clients to have successful websites regardless of the hosting plan they use. As a result, creating a contact form using PHPMailer is possible on all of our hosting plans, including our free hosting package. The only requirement is to have an email account created through the Email Accounts section of the Control Panel. This email account will act as the sender of the messages created through our free form-to-email script example.
In order to create an email account, you need to be hosting a fully-qualified domain name. You can opt to purchase a premium domain name or you can get a free .DX.AM domain name through the Domain Manager section of the Control Panel. If you are not sure how to use the Email Accounts section of the Control Panel, you can check our in-depth guide on how to create an email account.
How to Create a PHPMailer Contact Form?
Once you have a working email account in your hosting space, you can start building your PHPMailer form-to-email script. Follow along as we show you how to set up a PHP contact form on your website:
- Head over to the official Github page for the PHPMailer project.
- Click on the Clone or download button.
- Choose Download ZIP, as shown in the screenshot below: