PHP Index

In order to become familiar with PHP programming structures and commands, we will build various PHP pages. Sections of this page will explain each PHP command, provide a link to a working sample, and detail the working sample's PHP code. Let's get started:

Mail Function

Let's send an email with PHP. To do so you will use the mail function. The mail function works with the following parameters:

mail(TO, SUBJECT, MESSAGE).

Let's breakdown each parameter. TO is the target email address. SUBJECT is what will appear in the subject line of the email. MESSAGE is the text of the email. Here's an example:

//variables for each parameter

$to = "mrchagoyan@hotmail.com";
$subject = "Feedback from your Website";
$message="Chagoyan, I think you should gives us all good grades in this class.";

//send the email

mail($to, $subject, $message);

Here's an example:sendmail.php ** USE YOUR OWN EMAIL! ** Mine is already cluttered. =)


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>sendmail.php</title>
</head>

<body>
<?php
echo "Thank you for sending a message!";


//send feedback to Mr. C.

//variables for each parameter
$to "mattsurber@live.com";  //this is the email
$subject "Feedback from your Website";  //this is the subject line
$message="Chagoyan, I think you should gives us all good grades in this class."//this is the message

//send the email (so simple!)
mail($to$subject$message) or print "**Message Not Sent - ABORTED! ABORTED! ABORTED! ABORTED!"
?>
</body>
</html>