Sending Emails

You can get the viewer to email you by using a http mailto:. This works well if they have an email program setup on their computer. If they happen to be on a computer in a public library, this will not do.

Another option is to use mail(). You can get very sophisticated with this function, but for the purposes of this class, we will keep it simple. Note that PHP must be configured to handle this function. Check with your domain host.

mail() has three attributes relating to the To: field, Subject: field and the Message: field. Define the three strings for each of those fields, include them as attributes, call the mail() function and you're done. Here's an example:

<?php $To = "me@myOffice.biz"; $Subj = "Web Page Comments"; $Message = "A link is not working on your home page."; if (mail($To,$Subj,$Message)) { echo "Mail sent!"; } else { echo "Mail failed!"; } ?>

You can place this strategically on your page and you have your response setup. I say "strategically" because you do NOT want to put the code as it appears above. If you did, then every time your page was accessed, you would be sent an email. You need to make it a function and only call it if the viewer clicks on a button or something.

To send to more than one addressee, include complete addresses separated by commas (not separated by semi-colons as many email programs do, like Outlook). So, in the example above, we could instantiate as follows: $To = "me@myOffice.biz,you@yourOffice.biz,him@hisOffice.biz";, and the message would go to all three.

That hits everything you need to know about mail(). For an example of a more sophisticated use of this same function, see this emailer I found on the internet (I did not write this code).


Sessions   < <  PREVIOUS   Table of Contents NEXT  > >   PHP/MySQL Interface

Developed with HTML-Kit
Sandersongs Web Tutorials
Contact the Webmasterwith comments.
©2017, by Bill Sanders, all rights reserved.
This domain had 3,996 different visits in the last 30 days.
435,562 hits on this domain since 24 Nov 2006.
http://www.sandersongs.com/PHPsqlCourse/PHP13.php
This page was last modified on our server on 4 Jun 2008
and last refreshed on our server at 3:56 am, MST
This file took 0.01048 seconds to process.