Written by Dany Matta



Autoresponders With PHP

Written by Robert Plank

First off, check outrepparttar URL below. You'll learn how to make that today. utorials/3/signup.html

Fill out your e-mail address onrepparttar 105088 page you see. (I promise it's not being saved anywhere.) Then, wait a minute or two and check your mail. You should get a message from Gumby ( containing a sample autoresponder message.

Today, we're going to learn three easy things: redirection, mail sending, and form submission.

When we finish with that, you will know how to put those components together and create an autoresponder. Because if you think about it, that's all an autoresponder does. Somebody enters in their e-mail address, are sent an e-mail message, and then are redirected to a new page.

Of course there are more complex autoresponders, like Gary Ambrose's Opt-In Lightning, or Wes Baylock's Mail Master Pro which handle multiple follow-ups and recordrepparttar 105089 e-mail addresses of those who have signed up forrepparttar 105090 responder. But today we're just going to focus on how to make a very basic, very simple autoresponder.

Hopefully, you've seen what form objects in HTML look like. Here's some code you can use for an example:

Enter Your E-Mail Address:

Copy and paste this code into a file called "signup.html" and upload it to your web server. You'll see a text box waiting for your visitor to enter his or her e-mail address so they can be sent that autoresponse message.

Of course,repparttar 105091 form won't work just yet because, if you look atrepparttar 105092 first line of that HTML code I gave you, you'll see thatrepparttar 105093 form submits to a script called "some-script.php". And we haven't made that just yet.

Look onrepparttar 105094 second line of "signup.html", atrepparttar 105095 last half ofrepparttar 105096 line. You should be familiar with HTML tags, but if you're not, an HTML tag consists of two parts:repparttar 105097 parent tag andrepparttar 105098 attributes.

The parent tag is simplyrepparttar 105099 tag's designation. For example, if you had a slice of HTML code that looked like this:

Thenrepparttar 105100 parent tag would be "font". The rest of what's enclosed inrepparttar 105101 tag tellsrepparttar 105102 browser what to do with it. For example, in this tagrepparttar 105103 attributes are thatrepparttar 105104 font should be Verdana with size 1.

Why am I telling you all this? Because it relates torepparttar 105105 HTML code you see in signup.html.

Now, when you look at this:

The code tellsrepparttar 105106 receiving browser that this is an "input" tag, meaning that it's a form field. The name of this item is "email" and its size is 30, meaning this text box should be 30 characters in width.

Whenrepparttar 105107 form is submitted, it takes allrepparttar 105108 values of allrepparttar 105109 fields inside that form and throws it at its destination. In this case, our destination is "some-script.php".

If you're lost, this will all make a whole lot more sense once you try this next step.

Make a file called "some-script.php" and paste this line of code into it:

Uploadrepparttar 105110 script inrepparttar 105111 same folder as signup.html, and go to "signup.html". Type your e-mail address in and clickrepparttar 105112 submit button.

You should see a new page containing just your e-mail address and nothing else.

Is this starting to make sense? You toldrepparttar 105113 PHP script to dumprepparttar 105114 contents ofrepparttar 105115 variable called "email" torepparttar 105116 screen, and you just submitted a form with a text box called "email".

If you want to try one more exercise like this, changerepparttar 105117 name ofrepparttar 105118 text box to, say, "goober" in signup.html and changerepparttar 105119 $email in some-script.php to $goober. Upload both, go to signup.html, and type anything intorepparttar 105120 text box. You'll getrepparttar 105121 same result.

This is how you'll pass data from forms (like text fields, drop down menus, radio buttons andrepparttar 105122 like) along intorepparttar 105123 PHP scripts you create.

We've just covered how to submit form elements into PHP. Now let's focus on sending mail.

PHP has a really simple function that uses whatever mail sending program is installed on your server to send messages torepparttar 105124 outside world. If you have a crappy web server, this step might not work and you'll have to use a different web host if you want to try this.

But if you're on a good web host that has PHP installed *correctly*, this shouldn't be a problem.

Up until now we haven't used functions in PHP too much, aside from simple things like include() and header(). Today's your lucky day, because functions work in a very similar way to HTML tags. You haverepparttar 105125 parent tag, andrepparttar 105126 attributes (or parameters).

The mail() function basically works like this:


Let's start off by sending a simple e-mail message to yourself. We won't need any special headers this time around, so this will be quick and painless. Copy this one line of code into "mailtest.php":

Cont'd on page 2 ==> © 2005
Terms of Use