# html FormMail



## bella (Feb 2, 2004)

hello, I keep getting an error message saying connection failure has occured with this code. Can anyone take a look and see what's the problem. Thanks

 <form method="post" action="mailto:info@maddogpro.com"
enctype="text/plain">
<input type="text" name="Name" size="20" maxlength="40"> 
<input type="text" name="E-Mail Address" size="20" maxlength="40">
<input type="submit" name="Newsletter" value="Sign Up">
</form>


----------



## uoba (Feb 2, 2004)

What are you expecting this form to do? 

The way you have it at present, it will open up the user's e-mail app (Outlook Express, Mail.app or whatever) and input the form details in a new e-mail. such as:

```
Name=Name
E-Mail Address=Whatever
Newsletter=Sign Up
```

It's then up to the user to send the e-mail.

Is this what you want?


----------



## mdnky (Feb 2, 2004)

You need to run a script to properly do that.

 Can you run PHP or CGI scripts off your host? Your host may already have a preinstalled script for you to use, since it's a popular item...so check out their FAQs or features list. Otherwise, you can find plenty of CGI, PHP, etc. scripts on the net for form to email.

 The attachment is a simple PHP one based on one I use on a real estate site. Should be pretty easy to see how it works, a copy of the PHP file and the HTML for the form is in the zip. Use it if you like.  At the bottom of the PHP script you need to setup the URL of your thankyou page, where you want the user redirected after submission of the form.  Everything else should be ready to go.


----------



## bella (Feb 3, 2004)

Thanks for the file...I'll give it a try


----------



## habilis (Feb 4, 2004)

yeah, I just posted a thread similar to this one, I'll try it out as well. Is PHP superior to html for form submissions? and Why?


----------



## mdnky (Feb 5, 2004)

HTML is a tag based language for layout of elements, such as text and images.  Basically just tells the browser how to display everything.  It's interperated by the browser on the user's machine, hence why we all know about those nasty inconsistencies between IE, NN, Moz, Safari, Opera, etc.

PHP is an advanced scripting language for handling 'program-like' functions that runs on the server.  In order to process the information from the form, and submit it to an e-mail address, you need the script.  Think of it as a traffic guard of sorts, directing the info to where it should go.  The MacOSX.com forums are PHP based for example.  In that case it's used for various activities (posting, database intergration, authentication, etc.).

There's other types of scripts to do mail functions from forms out there, based on other variants like CGI, PERL, Python, ASP, ASP.net, Java, etc.  I personally prefer PHP, though any of those could do it.  I've messed with CGI and PERL (long, long time ago...1993), but PHP is just a better solution IMHO.  ASP is M$, so I stay as far away as possible.  

That and the host I use has xServes or PowerMac G5s for servers runing OS X Server.  On any *nix platform, PHP is the logical choice.  In fact, I do remember hearing something about it being the most popular app language for the net (something like 40% of sites) but that was a year or so ago.  M$'s ASP.net has made some big gains recently, which is regretable.


----------



## bella (Feb 5, 2004)

Thanks for the script. It works, but for some reason the name and email address are not appearing. Do I have to change my code in the form or the script?


----------



## mdnky (Feb 5, 2004)

I'm assuming you mean on the form web page.  I didn't put anything in there other than the simple form elements, figuring you'd be able to see how the script works.   My bad on not telling you that.

You could use <p> or another tag, or even a table (..wince..).  I normally use a HTML tag and control everything with CSS, since forms are not really proper data for tables.

<form name="newsletter" method="post" action="mail.php">
 <p>Name:</p>
	<input type="text" name="Name" size="20" maxlength="40">
 <p>E-Mail:</p>
	<input type="text" name="E-Mail" size="20" maxlength="40">
	<input name="send" type="submit" value="Submit">
</form>


----------



## Arden (Feb 5, 2004)

PHP will automatically use the form elements' names as variable names, so you have to make sure each PHP $variable is the same as the HTML name="variable".  If you change it, the values won't go through.


----------



## mdnky (Feb 5, 2004)

If you meant the 'from' as in the message in your e-mail box, I forgot to change the code as follows:


```
mail($to, $subject, $message, "From: $name <$email>\nX-Mailer: PHP/" . phpversion());
```

should be


```
mail($to, $subject, $message, "From: $Name <$E-Mail>\nX-Mailer: PHP/" . phpversion());
```


----------



## bella (Feb 5, 2004)

yeah... It should work now.


----------



## bella (Feb 5, 2004)

sorry to be so needy, but now in my inbox it says from- mail@cws-5.ampira.com


----------



## mdnky (Feb 5, 2004)

That's the server's address, as the mail originates there.  I never worried about it since the e-mail address of the client is contained in the message.  That and I do believe most servers now override an e-mail specified in a form as a method of SPAM protection.

On my version I have it setup so that any messages from the form contain [tomowens.com] in the begining of the subject, then the e-mail program seperates everything out.  Also, mine always does "Mail@xrack.xrackhosting.com", with the name in front of it.

John Doe <Mail@xrack.xrackhosting.com>

So, unless you changed alot, the e-mails off your form should look like this:

*
From: Willie Nelson <mail@cws-5.ampira.com>
Date: Thu Feb 05, 2004  03:56:16 PM US/Eastern
To: info@maddogpro.com
Subject: [Newsletter] Signup Notice

The following information has been provided:

Name: Willie Nelson
E-Mail Address:  w.nelson@music.com
*


----------



## bella (Feb 5, 2004)

I'm not getting any name or email address?


----------



## mdnky (Feb 5, 2004)

Copy and paste the HTML from you page (entire form) or a link to it on the server.


----------



## bella (Feb 6, 2004)

<form name="newsletter" method="post" action="mail.php">
<p align="center" class="style2"><span class="style11">Name:</span>
  <input type="text" name="Name" size="20" maxlength="40" />
</p>
<p align="center" class="style2"><span class="style11">E-Mail:</span>
    <input type="text" name="E-Mail" size="20" maxlength="40">
    <br />
    <br />
    <input name="send" type="submit" value="Submit">
  </p>
</form>


----------



## mdnky (Feb 8, 2004)

bella said:
			
		

> I'm not getting any name or email address?



Where?  On the form or in the e-mail (see below)?

If in the e-mail, as the e-mail address & subject or in the body of the message?


----------



## bella (Feb 9, 2004)

as the email... I'm getting the correct subject info, but no from info, or in the body of the message, just this- 
The following information has been provided:

Name: 
E-Mail Address: -Mail


----------



## mdnky (Feb 9, 2004)

```
mail($to, $subject, $message, "From: $Name <$E-Mail>\nX-Mailer: PHP/" . phpversion());
 header( "location: http://www.yoursite.com" ); //url to re-direct to after mail has been succesfully sent.
 ?>
```

Make sure the last three lines in the PHP file look like that.  Pay attention to the case and any ' or " s.

I'm betting on something missing there.


----------



## habilis (Feb 10, 2004)

weird. I'm getting this error
Parse error: parse error in /www/transitbroker.com/mail.php on line 9
same thing when I test on my other server

Here is my form code:
<form name='newsletter' method='post' action="mail.php">
	<input type="text" name="Name" size="20" maxlength="40">
	<input type="text" name="E-Mail" size="20" maxlength="40">
	<input name="send" type="submit" value="Submit">
</form>



And here is my PHP code:

<?
$to = "aaron@bonkdown.com"; // E-mail address to send mail to.
$subject = "[transitbroker.com] Form Results"; //Subject of the e-mail
$message = "The following information has been provided:

Name: $Name
E-Mail Address: $E-Mail";							

mail($to,*$subject,*$message,*"From:*$Name*<$E-Mail>\nX-Mailer:*PHP/"*.*phpversion()); 
*header(*"location: http://www.bonkdown.com/"*);*//url to re-direct to after mail has been succesfully sent. 
*?>


----------



## mdnky (Feb 10, 2004)

Look at post 19...for some reason what you posted has a bunch of *'s in it that shouldn't be there.

What program are you using to upload the script?  (Make sure it's using ASCII mode and not Binary mode for the upload.)  How about editing them?  Somewhere those *'s appeared...now where is the question of the day.


----------



## habilis (Feb 10, 2004)

No problem. I actually ended up downloading a program called Forms to Go X by Bebosoft(http://www.bebosoft.com). It automatically creates the script for me in PHP,ASP, or PERL so now I can relax and concentrate on design. 

As for the *'s appearing there... I have no idea how that happened, I just copied and pasted right out of the dreamweaver window.


----------



## bella (Feb 12, 2004)

I think I'll do the same. Cool site!


----------

