Guide to PHP and MySQL (University at Buffalo 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 gmail.com.
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 PHPMailer.zip
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 = "username@gmail.com";
//Password to use for SMTP authentication
$mail->Password = "yourpassword";
//Set who the message is to be sent from
$mail->setFrom('from@example.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('whoto@example.com', 'John Doe');
gmail.php
SettingsSending 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.