spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / php / phpemail / 4 To page 1To page 2To page 3current page
[previous]

Email Forms in PHP

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

Compiling and Sending the Email

Look at the else in the final if statement:

else
{
	$message = "Name: $Name\nEmail: $Email\nComments: $Comments\n";
	$extra = "From: $Name\r\nReply-To: $Email\r\n";
	mail ("noone@nowhere.com", "Website Email", $message, $extra);
	echo "<p class=bodymd>Thanks for your inguiry, $Name.</p>";
	echo "<p class=bodymd>A response will be sent to $Email as soon as possible.</p>";
}

The first line sets the body of the email. This is where it takes the values of all the fields, which are variabilized with the field name preceded by a "$," so the field name "Name" is known to PHP as "$Name." The \n, as most of you I am sure know, starts the text on the next line. Therefore, $message = "Name: $Name\nEmail: $Email\nComments: $Comments\n"; will result in this message body:

Name: {value of Name field}
Email: {value of Email field}
Comments: {value of Comments field}

The second line is not necessary to send email, but it is convenient to use, as it sets the "from" and "reply-to" fields in your email client. It's a neat feature.

Now sending the email, you won't believe how easy this is. All it takes is:

mail ("noone@nowhere.com", "Website Email", $message, $extra);

The "mail" statement sends the defined values to the sendmail program configured in you Web server. The first value is where the email gets sent to, the second is the subject of the email, the third is the body of the message that you complied above, and the last is the "from" and "reply-to" statement from above...thats it!

Now how easy was that?!

Final Thoughts

PHP has really renewed my interest in my profession. It has promise of adding new life to my Web sites. I have been working with MySQL integration and administration as well as permissions and password protection. All tasks have been enjoyable, interesting and relatively quick and easy. I really think any real Web geek like myself will find great fun in learning the powerful features and functions that PHP has to offer, and on top of it all, PHP, MySQL and Apache are all free! If that doesn't help to spark your curiousity level, I doubt anything will.

####

About the author:

Dan Ball is very involved in Web development and the music industry and has produced recordings, streaming media and Web sites for several musical artists worldwide. Currently he operates his own audio production and Web development business, dB Masters Audio Prod. (http://www.dbmasters.net). He can be contacted at dbmasters@excite.com.

home / programming / php / phpemail / 4 To page 1To page 2To page 3current page
[previous]


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Search Engine Optimization: Selecting and Embedding Keywords · Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
IBM DB2 10 for z/OS: Justifying the Upgrade · Living La Vida Colo: Choosing the Right Colocation Facility · FTC Concerns over Social Media Privacy Linger


Created: July 30, 2001
Revised: July 30, 2001


URL: http://webreference.com/programming/javascript/phpemail/4.html