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 = ""; $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 = ",,";, 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.
©2024, by Bill Sanders, all rights reserved.
This domain had 4,985 different visits in the last 30 days.
This page was last modified on our server on 11 Jul 2021
and last refreshed on our server at 11:49 am, UTC
This file took 0.02006 seconds to process.