|
This function first assembles the e-mail address using
the name passed to the function and your hard-coded domain name. Next
it creates a text string containing the <A HREF> tag to be displayed
on the page. Finally, the link is written to the page.
The result is an e-mail link that looks and acts exactly
as if it was normal mailto link:
.
There is no e-mail link for a bot to harvest though: the name is only
shown in the function call, and the mailto link is assembled and generated
as the page loads.
What if the the page visitor has turned off JavaScript
in the browser? Well, this won't work of course. You can add <noscript>
tags to let these people know what's going on: a warning message, a suitably
garbled version of the address that humans can read (but bots can't),
or an image of the e-mail address text (don't blow it by using the address
as the alt attribute!).
<noscript>
<p>To guard against spam, e-mail addresses
on this page are encoded using JavaScript.
Please turn on scripting in your browser
to see e-mail addresses.</p>
<p>name[@@AT@@]yourdomain[..DOT..]com</p>
<img src="emailaddress.gif" alt="e-mail address">
</noscript>
Subscribing visitors to a mailing list using PHP
An e-mail announcement or discussion list is a cheap and easy way to communicate
with customers, users, or like-minded individuals. To set up an e-mail
list, you'll need to use a mailing list manager, which many web hosts
now provide. Once the mailing list is set up, make it easy for people
visiting your web site to sign up. A quick and easy way to do this is
using the PHP mail() function. For this example, we're using PHP 4 and
EZ Mailing List Manager, this popular list manager similar to LISTSERV
or Majordomo.
Once you've set up an EZ list, a user can subscribe to
a list by sending an e-mail message to a special address. For example,
if joe@yahoo.com wants to subscribe to the news@flanneljammies.com list,
he sends an e-mail message to news-subscribe-joe=yahoo.com@flanneljammies.com.
Our job is to simplfy this process for Joe. To make it easy for Joe, we'll
create a small form so he can type in his e-mail address and click the
Sign Up button.
Create a PHP document called signup.php and paste in
the code below. This code creates an HTML form that posts to itself (signup.php).
If an address has been entered, the script validates it, assembles the
special subscription address, calls the mail() function, and displays a thank-you
message. If the form has been posted without any address or the address
is invalid, the script displays warning messages. If this is the first
time the page has been displayed or there are errors with the submission,
the script displays the form fields for user entry.
|