PDA

View Full Version : form mail script help



Mehok
10-25-2006, 01:42 PM
I am not much in php can anyone create me a form mail code in php for the fields

Name:
Surname:
Address: (Optional)
Tel: (Optional)
Reason for contact:
Message:

Please note the fields are in a table structure like
__________ __________
|__________|__________|
|__________|__________|
|__________|__________|

as far as the code is there is no text infornt the field

<input type="text" name="Name" id="Name:" value="Enter Full Name" size="25"
maxlenght="30" />
<input type="text" name="Surname" id="Surname:" value="Enter Full Name" size="25"
maxlenght="30" />
<input type="text" name="Address" id="Address" value="Address:" size="25"
maxlenght="30" />
<input type="text" name="Address" id="Address" value="Address" size="25"
maxlenght="30" />
<input type="text" name="Address" id="Address" value="Address" size="25"
maxlenght="30" />
<input type="text" name="Reason" id="Reason" value="Reason For Contact:" size="25"
maxlenght="30" />
<textarea name="textanimal" ID="textanimal" rows="5" cols="40">Message you want to send to us</textarea>

thetestingsite
10-25-2006, 06:45 PM
This is a fairly simple formmail script. It does not do any verifications or what not but you should be able to edit it by looking at PHP.net (http://php.net) or some other websites that have PHP tutorials. Just set the HTML form action to go to contact.php and make the following page as that.

contact.php


<?php
//edit the following

$to = "nobody@mydomain.com"; //your email address
$subject = "Contact Form from Website"; //the subject of the email


//Get the variables

$name = $_REQUEST[Name];
$sname = $_REQUEST[Surname];
$addr1 = $_REQUEST[Address1];
$addr2 = $_REQUEST[Address2];
$addr3 = $_REQUEST[Address3];
$reason = $_REQUEST[Reason];
$message = $_REQUEST[textanimal];

$msg = <<<HERE
The following information was submitted from the contact form on your website.

Name: $name

Surname: $sname

Address: $addr1
$addr2
$addr3

Reason for Contact: $reason

Message:

$message

HERE;

//edit the above to be the message that is sent to you


if (@mail($to,$subject,$msg)) {
echo 'The email was sent successfully!';
}

else {
echo 'The email was not sent because of an error!';
}

//thats all!!!!
?>


have fun!

Mehok
10-25-2006, 09:21 PM
thanks i seriously cannot figure out this ****

hopefully this will get me off to a grate start

thetestingsite
10-25-2006, 09:28 PM
Just let me know if you need any help with it.

Mehok
10-26-2006, 02:23 PM
I just got tha form uploaded it gives me a message that the form was sent but i aint getting it

tomyknoker
10-26-2006, 11:19 PM
Just let me know if you need any help with it.Hi There... This looks like exactly what I need but I couldn't figure out the form side? Is it easy to incorporate this into the attached form? I tried but to no avail... :confused:

thetestingsite
10-27-2006, 12:36 AM
Mehok, perhaps your server does not have SMTP on it, or at least sendmail I should say. A way that you can see if it is something with the script is by changing the following line:



if (@mail($to,$subject,$msg)) {


to this:



if (mail($to,$subject,$msg)) {


notice I took the "@" sign from the front of mail(). This will now display any error messages if there are any errors.

tomyknoker,

this formmail script should work with it, all you would have to change is the first part to suit your needs.

Example:


//Get the variables

$text1 = $_REQUEST[textfield1];
$text2 = $_REQUEST[textfield2];
$check1 = $_REQUEST[checkbox1];
$tarea1 = $_REQUEST[textarea1];

//add more if needed


the $_REQUEST['yourfieldname']; gets the value that was submitted in the form then assigns a variable for you to use in the php script.

tomyknoker
10-27-2006, 01:03 AM
Mehok, perhaps your server does not have SMTP on it, or at least sendmail I should say. A way that you can see if it is something with the script is by changing the following line:



if (@mail($to,$subject,$msg)) {


to this:



if (mail($to,$subject,$msg)) {


notice I took the "@" sign from the front of mail(). This will now display any error messages if there are any errors.

tomyknoker,

this formmail script should work with it, all you would have to change is the first part to suit your needs.

Example:


//Get the variables

$text1 = $_REQUEST[textfield1];
$text2 = $_REQUEST[textfield2];
$check1 = $_REQUEST[checkbox1];
$tarea1 = $_REQUEST[textarea1];

//add more if needed


the $_REQUEST['yourfieldname']; gets the value that was submitted in the form then assigns a variable for you to use in the php script.hi there! thanks for the info... i can't get it to work with my form :( any chance you could show mne the html code for the whole thing on my form? i'm getting myself really confused...

thetestingsite
10-27-2006, 03:14 AM
Use the following as a start:

contact.html


<html>
<head>
<title>Contact.html</title>
</head>
<body>

<!--Start the form-->
<form action="contact.php" method="POST">
Text1: <input type="text" name="text1"> <BR>
Text2: <input type="text" name="text2"> <BR>
<input type="checkbox" name="checkbox1" value="check1"> Checkbox1
<input type="checkbox" name="checkbox2" value="check2"> Checkbox2 <BR>
<textarea name="textarea1">This is called textarea1</textarea>
<BR><BR>

<input type="submit" value="Submit Form">
</body>
</html>


contact.php



<?php
//edit the following

$to = "nobody@mydomain.com"; //your email address
$subject = "Contact Form from Website"; //the subject of the email


//Get the variables


$text1 = $_REQUEST[text1]; //variable for form field text1
$text2 = $_REQUEST[text2]; //variable for form field text2
$checkbox1 = $_REQUEST[checkbox1]; //variable for form field checkbox1
$checkbox2 = $_REQUEST[checkbox2]; //variable for form field checkbox2
$textarea1 = $_REQUEST[textarea1]; //variable for form field textarea1

$msg = <<<HERE
The following information was submitted from the contact form on your website.

Text1: $text1
Text2: $text2
Checkbox1: $checkbox1
Checkbox2: $checkbox2
Textrea1:

$textarea1
HERE;

//edit the above to be the message that is sent to you

$sent = mail($to,$subject,$msg); //try to send the message

if ($sent) { //if the email was sent
echo 'The email was sent successfully!';
}

else { //if it was not sent
echo 'The email was not sent because of an error!';
}

//thats all!!!!
?>


That should at least be a start for you. Simply modify the two files to suit your needs.

tomyknoker
10-27-2006, 03:16 AM
Use the following as a start:

contact.html


<html>
<head>
<title>Contact.html</title>
</head>
<body>

<!--Start the form-->
<form action="contact.php" method="POST">
Text1: <input type="text" name="text1"> <BR>
Text2: <input type="text" name="text2"> <BR>
<input type="checkbox" name="checkbox1" value="check1"> Checkbox1
<input type="checkbox" name="checkbox2" value="check2"> Checkbox2 <BR>
<textarea name="textarea1">This is called textarea1</textarea>
<BR><BR>

<input type="submit" value="Submit Form">
</body>
</html>


contact.php



<?php
//edit the following

$to = "nobody@mydomain.com"; //your email address
$subject = "Contact Form from Website"; //the subject of the email


//Get the variables


$text1 = $_REQUEST[text1]; //variable for form field text1
$text2 = $_REQUEST[text2]; //variable for form field text2
$checkbox1 = $_REQUEST[checkbox1]; //variable for form field checkbox1
$checkbox2 = $_REQUEST[checkbox2]; //variable for form field checkbox2
$textarea1 = $_REQUEST[textarea1]; //variable for form field textarea1

$msg = <<<HERE
The following information was submitted from the contact form on your website.

Text1: $text1
Text2: $text2
Checkbox1: $checkbox1
Checkbox2: $checkbox2
Textrea1:

$textarea1
HERE;

//edit the above to be the message that is sent to you

$sent = mail($to,$subject,$msg); //try to send the message

if ($sent) { //if the email was sent
echo 'The email was sent successfully!';
}

else { //if it was not sent
echo 'The email was not sent because of an error!';
}

//thats all!!!!
?>


That should at least be a start for you. Simply modify the two files to suit your needs.Thanks so much! So with the form.html... What code do I put on the submit button?

thetestingsite
10-27-2006, 03:30 AM
nothing more, also I forgot to close the form tag in the html file. All the submit button needs is two attributes (more if using javascripts or DHTML scripting) the type (submit) and the value (Click here to Send!). After the submit button, if you do not have any other for items, you should close the form tag by adding </form> at the end. I forgot to do so in the example above, due to the fact that I just typed that up.

tomyknoker
10-27-2006, 03:36 AM
nothing more, also I forgot to close the form tag in the html file. All the submit button needs is two attributes (more if using javascripts or DHTML scripting) the type (submit) and the value (Click here to Send!). After the submit button, if you do not have any other for items, you should close the form tag by adding </form> at the end. I forgot to do so in the example above, due to the fact that I just typed that up.I'm a bit confused sorry... So the two pieces of code you showed me do they go into the same file? Once the user clicks submit on the form how does it know what to do?

thetestingsite
10-27-2006, 03:39 AM
k...they are two completly separte files. the first one is an HTML document called contact.html. When the user click submit on that form, then the form uses the action (located in the <form> tag) - in this case it's contact.php. The second piece of code is contact.php.

tomyknoker
10-27-2006, 04:12 AM
I got this error when I clicked Submit


Parse error: parse error, unexpected T_SL in e:\USERS\freewheelin\www\content\contact.php on line 27

sartajc
10-27-2006, 04:56 AM
I would just recommend using this: http://www.eformmailer.com/ . its a free wizard that makes a PHP form for you.

tomyknoker
10-27-2006, 05:17 AM
I would just recommend using this: http://www.eformmailer.com/ . its a free wizard that makes a PHP form for you.I still get errors using the free wizard... and also it redirects to a plain page...
Message could not be sent.
Mailer Error: Language string failed to load: instantiate

Thanks!
Your mail has been sent.

tomyknoker
10-27-2006, 05:26 AM
I got this error when I clicked Submit


Parse error: parse error, unexpected T_SL in e:\USERS\freewheelin\www\content\contact.php on line 27Anyone know what this error could be referring too?

thetestingsite
10-27-2006, 05:46 AM
I've tried the code on my home server and it works perfectly (with the exception of the mail part being that I dont have a mail server yet.) Although I have also tried it on my website's server and it had worked perfectly on that as well...check to make sure you have not added any spaces before or after the ending HERE; those are the only times that I recieved an error about it.

tomyknoker
10-27-2006, 05:47 AM
Could you take a look at the file? It's wierd I just used your two files, without changing a thing and no luck... You can test it here http://www.tomsynnott.com/email_form/contact.htm

thetestingsite
10-27-2006, 05:49 AM
link broken 404 error (cannot find page)

UPDATE: works now, and I checked it, now it says unexpected T_STRING on line 17... line 17 is the variable $msg.....check to make sure the last line before this one is ended by a semicolon (;) also, as i said before I used it on my home server once again and still cannot reproduce the error message.

Another UPDATE: i reproduced the error, make sure the the $msg variable is a line or two below the last $_REQUEST[field]; or delete the comment behind that one. That was the only thing that I could see

Mehok
10-27-2006, 08:46 AM
ok so the server that i am supose to host on is supose to have PHP, STMP, and of course JAVA and HTML support

thetestingsite
10-27-2006, 03:52 PM
PHP....yes.....HTML will work on mostly any server, SMTP..or at least sendmail....Java....if you have JAVA apps that you need to use....

chechu
10-30-2006, 01:05 PM
Just place this:

<INPUT TYPE="submit" NAME="Submit" VALUE="send" style="border: 1px solid #666666; width:107; background-color:'#eeeeee';">