Click this widget to change the font size.
Click this widget to change contrast.

Home Page 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | Links | Search | Bio |

Guide to PHP and MySQL (Buffalo State College Version)

Chapter 11: Sending Email with PHP

PHPMailer function provides a set of class objects you can ue to send an email message from your web site. To send email, you must have an account on SMTP (Simple Mail Transfer Protocal) mail server, such as

Using PHPMailer on your localost Server.

To send email from your localhost server via a Gmail account, download the latest version of PHPMailer from GitHub (source code (zip)). Extract the file to your \www\PHPMailer\ folder.

Then you shuld try sending email. First, copy \www\PHPMailer\examples\gmail.phps to www\PHPMailer\examples\gmail.php. Then, edit this gmail.php file and change these values to your gmail account information:

//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "";

//Password to use for SMTP authentication
$mail->Password = "yourpassword";

//Set who the message is to be sent from
$mail->setFrom('', 'First Last');

//Set an alternative reply-to address
$mail->addReplyTo('', 'First Last');

//Set who the message is to be sent to
$mail->addAddress('', 'John Doe');
Figure 11-1: gmail.php Settings

Sending Email with PHPMailer

See the \www/PHPMailer\examples\ for various examples of sending email using PHPMailer.

Task - Send an Email Using PHP

For this task you will create a web form that accepts the first name, last name, and email fields. You should validate the fields using both JavaScript on the front-end and PHP on the back-end. Display appropriate messages if any fields are in error. When the form is submitted, and the data validated, your PHP back-end should send an email to the email address from the form and include the user-entered data ($_POST array) in the body of the message.

You will modify the PHP function for this item in your index.php page to add a link to your web site files that allows me to view your work.

You *MUST* use the W3C Unicorn Validator to validate your HTML5/CSS3 code.