Free Article HomeSubmit Article l Contact Us


Autoresponders With PHP 
First off, check out the URL below. You'll learn how to make that today.
http://www.jumpx.com utorials/3/signup.html

Fill out your e-mail address on the 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 (null@jumpx.com) 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 record the e-mail addresses of those who have signed up for the 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, the form won't work just yet because, if you look at the first line of that HTML code I gave you, you'll see that the form submits to a script called "some-script.php". And we haven't made that just yet.

Look on the second line of "signup.html", at the last half of the line. You should be familiar with HTML tags, but if you're not, an HTML tag consists of two parts: the parent tag and the attributes.

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



Then the parent tag would be "font". The rest of what's enclosed in the tag tells the browser what to do with it. For example, in this tag the attributes are that the font should be Verdana with size 1.

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

Now, when you look at this:


The code tells the 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.

When the form is submitted, it takes all the values of all the 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:



Upload the script in the same folder as signup.html, and go to "signup.html". Type your e-mail address in and click the submit button.

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

Is this starting to make sense? You told the PHP script to dump the contents of the variable called "email" to the screen, and you just submitted a form with a text box called "email".

If you want to try one more exercise like this, change the name of the text box to, say, "goober" in signup.html and change the $email in some-script.php to $goober. Upload both, go to signup.html, and type anything into the text box. You'll get the same result.

This is how you'll pass data from forms (like text fields, drop down menus, radio buttons and the like) along into the 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 to the 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 have the parent tag, and the attributes (or parameters).

The mail() function basically works like this:

mail("recipient","subject","body","headers");

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":



Replace "billg@microsoft.com" with your actual e-mail address, but be *sure* to keep quotes around it. Save it, and upload mailtest.php to your web server and run it in the browser. You should see a blank page. Wait a few minutes and check your mail. You should see a mysterious mail message in your box with the subject "Hello" and the message "Hi. This is the body of my message."

If you're using a free e-mail service or a weird ISP, the message won't come through because a lot of mail servers these days require that certain headers are present in the message.

Let's do that now.

What's below isn't important enough to explain thoroughly, but it's just header information that is interpreted by the mail server. This data tells us that we're sending a plain text e-mail, that the message came from your e-mail address (and gives your name), and tells us that the e-mail "client" we used was PHP.

$headers = "Content-Type: text/plain; charset=us-ascii
From: $myname <$mymail>
Reply-To: <$mymail>
Return-Path: <$mymail>
X-Mailer: PHP";

This is the code you should have by this point, complete with the header information and the variables which tell the script what your name and e-mail address are:


$email = "billg@microsoft.com";

$myname = "Your Name Here";
$mymail = "your@email.here";

$headers = "Content-Type: text/plain; charset=us-ascii
From: $myname <$mymail>
Reply-To: <$mymail>
Return-Path: <$mymail>
X-Mailer: PHP";

mail($email,"Hello","Hi. This is the body of my message.",$headers);

?>

Notice how we've simplified things a bit by using variables in the mail() function. That way we don't have to retype things. This method also looks better (in my opinion anyway) and is easier to tweak once you're ready to actually customize it for yourself.

Try this out again. Believe it or not, but you just made your first autoresponder! Before we move on let's make this look even cleaner:


$myname = "Your Name Here";
$mymail = "your@email.here";

$subject = "Hello";
$body = "Hi. This is the body of my message.
Notice how I can continue typing right on the next line!";

$headers = "Content-Type: text/plain; charset=us-ascii
From: $myname <$mymail>
Reply-To: <$mymail>
Return-Path: <$mymail>
X-Mailer: PHP";

if ($email != "") { mail($email,$subject,$body,$headers); }

?>

All I did here was just make things look nicer, but notice how I removed the line that set $email to "billg@microsoft.com." This is because the value of $email will be passed to the script from that form we made earlier.

This also sends the e-mail message ONLY if the value of $email is not blank. So if someone just hit the submit button without entering an address, the script won't try to send the e-mail message.

Everything should be ready for you to try out now. Re-upload "some-script.php" and go to signup.html. Enter your e-mail address in the field, hit submit and wait for that mail message to arrive.

There's only one step left to making this autoresponder complete. And that's sending the user somewhere so they aren't given a blank page.

Find this line in your script:
if ($email != "") { mail($email,$subject,$body,$headers); }

And paste this directly underneath it:
header("Location:http://www.jumpx.com"); die();

Try the autoresponder out. You'll see that once the autoresponse message is sent, you're directed to www.jumpx.com. Now, go ahead and change it to whatever URL you want to use. Or, make use it with a variable so the end result is like this:


$myredirect = "http://www.my-domain-name.com hankyou.html";

$myname = "Your Name Here";
$mymail = "your@email.here";

$subject = "Hello";
$body = "Hi. This is the body of my message.
Notice how I can continue typing right on the next line!";

$headers = "Content-Type: text/plain; charset=us-ascii
From: $myname <$mymail>
Reply-To: <$mymail>
Return-Path: <$mymail>
X-Mailer: PHP";

if ($email != "") { mail($email,$subject,$body,$headers); }
header("Location:$myredirect"); die();

?>

Don't forget to change the values above. "http://www.my-domain-name.com hankyou.html" needs to point to the URL where thankyou.html is stored.

You're done. Don't forget to send John feedback for me. If you're really curious as to how to do something in PHP, I might just write an article on it.


Author Info:

Article by Robert Plank PHP Newsletter: http://www.jumpx.com/newsletter Feedback? http://www.jumpx.com/feedback.php

 
30 Most Recent Articles :
A Disputed New Business:Virtual Property Exchange

In many ways, the in-game economy is similar to a real world economy - goods and services are traded to mutual advantage and are mediated in currencies(gold,platinum,credit,etc.). An online broker, who goes by the screen name Rolala, was not a fan of online games until his 15-year-old son be[ Read Article]

THE UNITED STATES, A Terrorist Nation

I love the United States of America, but I cannot tolerate the UNITED STATES OF AMERICA. No I am not shouting at you, I am simply making a distinction, a difference that thirty-seven states of the union have noticed and moved to rectify. You see, AMERICA isn’t America anymore, nor does it in anyw[ Read Article]

Dollars and Sense

When I speak of the Federal Reserve and the fiat monetary system that controls our lives I feel as though my words are falling on deaf ears. I have the sense that the simplest conversations suggesting that change must be made invoke fear and condemnation from my fellow citizens. When will we tak[ Read Article]

Constitutionality

Is the 16th Amendment constitutional? Of course it is, the Supreme Court has made that as clear as it did the issue of slavery. But let us remember that it took the lives of more than 365,000 brave American men and the destruction of the Republic to wrest the matter from the courts and resolve the[ Read Article]

Five Secrets to Effective Pay-Per-Click Advertising

With so many companies swarming the World Wide Web with their products, how can you and your products and services stand out? Your ready answer would most likely be effective marketing. But how? How can you catch the eye of a surfer skimming carelessly through web pages? How can you keep the at[ Read Article]

How to Sell Bonds

If you want to make good money with banks, or any institution, Government and agency bonds are where it is at. Simply because all Government bonds and agencies are AAA rated, and banks can buy millions of dollars of any bond without incurring any credit risk. All banks own bonds of some sort, a[ Read Article]

Closing in the Car Business

The “P” Word. Closing is all about helping car customers make positive decisions. It is not about pressure or manipulation. Your customers need help overcoming the “P” word. Procrastination! Procrastination is natural when it comes to making a buying decision. Your customer is trying to avoid [ Read Article]

If You Build It They Will Come, or Will They?

All right, so you invested your time and energy to build your organization a great new web site, but you are not getting quite the results you were hoping for. Few customers are visiting or interacting with you and rarely do you get prospects to contact you through the site. So what can you do to [ Read Article]

Confessions of a Yoga Teacher

The following are questions that Yoga teachers still need to answer, despite overwhelming evidence that Yoga is ?the mother of all health maintenance systems.? Mainstream thought is finally catching up, with the progress Yoga is making, but it has taken 5,000 years for us to get this far. Serio[ Read Article]

Vertical Creep in Search Results :: Should Organic Optimizers be Concerned?

I thought for this week I’d give a summary of some of the more interesting Search Engine Strategies sessions which are currently going on in New York City. I was at SES as a speaker last year in New York and I have to say, there is a wealth of information there even if some of it is contradict[ Read Article]

How to build link popularity fast and free

We all knew that back link or link popularity is a big factor to get good position in any search engines. But building link popularity some times really hard if you don't know how to do it. One of the hardest problem for new webmasters is to get back link to their newly stablis[ Read Article]

Does Chiropractic Care Really Make Sense?

The Role of Chiropractic in Treatment Beyond the Resolution of Symptoms Do you have the same nagging injury that never seems to go away? Are you suffering needlessly with pain? Are you fed up with taking painkillers? Do you want to find out what is causing your pain? If your answer is ‘ye[ Read Article]

The Economic Implications of Buying Drugs Online

Although the Internet is fairly new (at least to the mainstream) online shopping has grown by leaps and bounds. Now you can buy almost anything you need, from food to fishing equipment, right through your computer. Of course, this has meant that commerce has been forced to adapt to the changing co[ Read Article]

Manning and Manning-Can Either Brother Win the Big One?

It was just over a year ago, after the Colts lost to the Pats in their post-season contest, that Boomer Esiason said on national television, "I think maybe Peyton (Manning) is this generation's Dan Marino." Esiason went on to state that Manning "is a great football player, but he's not going to get[ Read Article]

Branding, Branding, Branding - MSN fails to keep it Straight

Sometimes you see promotions come along and you wonder: did they just do that? The current MSN promotion called msnsearchandwin is a prime example of this. Not only do they use “black hat” or at least “questionable” tactics on the site, but the messaging is inconsistent. In this article [ Read Article]

The New MSN Search Interface :: A positive change or the antithesis of transformation?

Now, instead of wide blue bars there are sleek silver-grey bars. Also, the top bar where the search box is became narrower. To me this makes the page seem less “closed in” and more visually appealing. I now feel as if I can trust the results more because they have more room. I’ve also noti[ Read Article]

Malta Holidays

With Malta visitor numbers static in recent years and facing new competiton from former Eastern Bloc countries offering cheap holidays, the recent announcement by the Maltese government that negotiations were at an advanced stage with two low cost airlines has[ Read Article]

Drug Rehab Treatment Centers as an Experience, not a Punishment

Choosing a drug rehab treatment center is a decision that calls for both negative and positive emotions. Nobody wants addiction to overtake their life to the point that rehab is the necessary step. However, the decision to go to one is something to look forward to, as it is the decision to rebui[ Read Article]

Some ways to improve your king content

There are thousands of articles, books and forum posts which showed that content is king in search engine optimization (SEO). In this article, you can find some ways that can help you improve this king content for your web site. * Content for people first, not for search engines - Some webmaste[ Read Article]

Aerosmith Just Keeps On Rockin’

For over three decades, Aerosmith have been one of rock's most revered and popular bands, crafting classic songs full of raw guitar runs and intensely energetic vocals. The band first reached fame in the 1970’s with a string of hits including "Dream On," "Sweet Emotion" and "Walk This Way." During t[ Read Article]

Chicago Cubs Pitcher Mark Prior Re-signs

After many trips through the rumor mill, Mark Prior accepted the Chicago Cubs’ offer on January 27 to a one-year, $3.65 million contract. That is $900,000 more than the salary he would have earned under the contract he voided in November. Since Prior's definitive season in 2003 (18-6), he has cooled[ Read Article]

Social Networking - The Next Great Marketing Medium?

There has been a virtual explosion of social networking sites in the past couple of years. Even the big players like Google, Yahoo and MSN are getting into it. With so much interest in how social networks work, one begins to wonder if there is marketing potential within these social network[ Read Article]

How to choose paid directory for web site listing?

How to choose paid directory for web site listing? Search Engines are the major source of traffic for any website. High search engine ranking can boost number of your visitors and in turn leads to increase in sales. The best way to get top search engine placement is to improve link popularity [ Read Article]

Addiction Treatment Centers Using Experiential Therapies

Life is experience. Substance dependence overtakes a person’s ability to make her own decisions to experience life, and life is no longer actively participated in. Therefore, in overcoming addiction, it is vital to learn to re-experience life. This lesson helps a treatment center resident reint[ Read Article]

The DH: Making Life Tough for AL Pitchers

In 1973 Major League Baseball instituted three rules designed to lessen the power of pitchers and create more offense. One theory at work was that the game needed to be energized and that more hitting would create additional runs and excitement. Both the National and American Leagues lowered th[ Read Article]

Vacation on the Beach the Smart Way

Vacation on the Beach the Smart Way Almost everyone agrees; there is no more relaxing way to vacation than to take it to the beach. For the vacationer/traveler who hasn't considered a beach house rental before, they represent an affordable and fun family oriented alternative. There is an intell[ Read Article]

Malta Holidays and Hotels Buzzed by New Jets

With Malta visitor numbers static in recent years and facing new competiton from former Eastern Bloc countries offering cheap holidays, the recent announcement by the Maltese government that negotiations were at an advanced stage with two low cost airlines has sparked hopes that the island will see [ Read Article]

The Rising Cost of Prescription Drugs

If you’re like many Americans, the rising cost of prescription drugs may be costing you your health. In particular, seniors living on a fixed income with no insurance are finding it difficult to pay for necessary prescriptions out-of-pocket, and as a result, may be failing to receive the treatment[ Read Article]

Who's Tops in Hockey and Who's Not

The National Hockey League needs to do more to encourage better coverage of the hockey games. With so many other sports realizing national coverage, the NHL is sometimes forgotten. However, this year, there's a race for the Stanley Cup, and only one is set to win it. But which team will that be? [ Read Article]

The Danger Of Rounding Up Your Debts

Rounding up your debts is one of the biggest dangers to your financial position. It's also one of the easiest ways for your debts to get out of control. This way of thinking is best summed up by the following comment; ‘I already owe $27500 so what’s another $500. It takes my debt to a nice round [ Read Article]

 

World Top Stories :
Nasa chief hails new era in space
The head of Nasa has hailed a "new era" in exploration after the launch of the first cargo delivery to the space station by a private company.


Ten jailed for Russian train bomb
A Russian court jails 10 people, four for life, for the November 2009 bombing of a high-speed train in which 27 people died.


Official 'offers 2012 tickets'
A senior Olympic official is suspended after a BBC investigation revealed he was willing to sell thousands of pounds worth of 2012 tickets for cash.


 

Copyright © 2006 Realook.com All Rights Reserved.