View Full Version : A PHP email (from html form) script
shining on 08-21-2005, 12:40 PM I know that this has been covered a zillion times before, but can anyone recommed a PHP email form that actually works properly.
I've tried googling, searching this forum and installed some things but I can't find what I want and when I do, it doesn't want to work properly. It's starting to annoy me and I'm getting impatient.
The main thing I'm looking for is something that redirects visitors to one page after they press the send button if everything is ok, or directs them to another page if it's not.
Many thanks,
Dale
thezeppzone 08-21-2005, 01:20 PM It took me a long time to find a proper one too...
Create a file called sendmail.php
Paste the following into it:
<?
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$comments = $_REQUEST['comments'] ;
$message = "Name: $name\nEmail: $email\n\n$comments";
mail( "email", "subject", $message );
header( "Location: http://www.done.html" );
?>
Things you need to change: the bold email is the email you want the form sent to, the subject is what you want it to come as, and done.html in bold is what page you want to show after the person clicks submit on the form, make sure its the full url with http://www. Based on what you see in there, it should be pretty self explanatory on how to add new things into it as per what you want your form to consist of.
Next, make your html page with your form, so for example with those inputs from the sendmail.php:
<form method="post" action="sendmail.php">
<tr><td>Name:</td> <td><input name="name" type="text" size="25"></td></tr>
<tr><td>Email:</td> <td><input name="email" type="text" size="25"></td></tr>
<tr><td>Comments:</td> <td><textarea name="comments" rows="3" cols="26"></textarea></td></tr>
<tr><td><input type="submit" value="Submit"></td></tr>
</form>
Once again edit those as to how you want them.
Lastly, make your done page to your liking, or just have it redirect them to an index or something. If you have any problems with this or are confused about anything just give me a shout, once I found a working script which was this one and finally figured out how to actually make it work, I have yet to have any problems.
Zepp
shining on 08-21-2005, 02:19 PM Many thanks for that Zepp, that's definately an improvement on the previous scripts i'd been using - no error messages with this one. Unfortunately, there are no emails either!
A script I tried before on another site I've done said it sent the message (albeit with an error blurb) and i tried this one on the new site and it said it sent, but didn't actually send. I'm thinking it might be something to do with this server? Is there something that should be 'switched on' when my hosting package was set up, that possibly hasn't been?
shining on 08-21-2005, 04:51 PM further to that last post, i have just tried uploaded it to another site and i get an email straight away, so it seems there is something wrong with the send mail function. does anyone know what version of php it requires?
pretender 08-21-2005, 06:28 PM Try adding php after the first question mark in the php script
Example:
<?php
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$comments = $_REQUEST['comments'] ;
$message = "Name: $name\nEmail: $email\n\n$comments";
mail( "email", "subject", $message );
header( "Location: http://www.done.html" );
?>
For some reason when i use php scripts it has to have <?php before the scripts works
shining on 08-21-2005, 10:06 PM thanks for the tip pretender, but still no luck.
This is from PHP.net. It should help you:
For the Mail functions to be available, PHP must have access to the sendmail binary on your system during compile time. If you use another mail program, such as qmail or postfix, be sure to use the appropriate sendmail wrappers that come with them. PHP will first look for sendmail in your PATH, and then in the following: /usr/bin:/usr/sbin:/usr/etc:/etc:/usr/ucblib:/usr/lib. It's highly recommended to have sendmail available from your PATH. Also, the user that compiled PHP must have permission to access the sendmail binary
Also, I think you can use <? --PHP CODE-- ?> , there shouldn't be any problem with that.
Hope this helps.
-Thomas
shining on 08-24-2005, 12:41 PM This is from PHP.net. It should help you:
Also, I think you can use <? --PHP CODE-- ?> , there shouldn't be any problem with that.
Hope this helps.
-Thomas
That seems like it might be the problem, or worth a try at least.
But where in the script would I type in the send-mail path?
shining on 08-24-2005, 12:56 PM UPDATE: this might help.
I set up a PHP info page (www.inmylife.co.uk/phpinfo.php) and it says the mail path is: "/usr/sbin/sendmail -t -i"
|