PDA

View Full Version : Forms



efq
20-02-2009, 02:18 PM
Hey,

I was wondering if anyone could help me with setting up a form on a page that I can recieve the data, for example.


Name:
Anything:
SEND
When they click send I get that info in my email or somewhere I can access.

I will try rep+ any help!

Thanks.

Sameer!
20-02-2009, 02:35 PM
<?php
if(isset($_POST["name"]) && isset($_POST["email"]) && isset($_POST["subject"]) && isset($_POST["query"]) && isset($_POST["other"]))
{

$name = $_POST["name"];
$email = $_POST["email"];
$other = $_POST["other"];
$query = $_POST["query"];

$message = "The following was sent from your contact form:

Name: $name

Email: $email

Query: $query

Other: $other";

$to = "[email protected]";
$subject = "MyForm Submission RE: ".$_POST["subject"]."";
mail($to, $subject, $message);

echo("Thank you! Your submission was sent successfully!");
}
else
{
echo('Fill out the form below to contact us. You will receive a reply within 24 hours.<br />
<form method="post" act="contact.php">
<fieldset>
<legend>Name</legend>
<input type="text" name="name" />
</fieldset>
<fieldset>
<legend>Email</legend>
<input type="text" name="email" />
</fieldset>
<fieldset>
<legend>Subject</legend>
<input type="text" name="subject" />
</fieldset>
<fieldset>
<legend>Query</legend>
<textarea rows="3" name="query"></textarea>
</fieldset>
<fieldset>
<legend>Other</legend>
<input type="text" name="other" />
</fieldset>
<br /><input type="submit" value="Contact Us" />
</form>');
}
?>


There you go! Took me 5 mins to code or so. :P

efq
20-02-2009, 02:55 PM
I am not a genius at these things, do I need to create a contact.php page and if so what does it need to include?

Cixso
20-02-2009, 02:57 PM
I am not a genius at these things, do I need to create a contact.php page and if so what does it need to include?

make a contact.php page and paste the code that the guy above showed you

efq
20-02-2009, 03:01 PM
make a contact.php page and paste the code that the guy above showed you
Ok I'll do that now, cheers.

efq
20-02-2009, 03:25 PM
Sorry for the double post.

I don't seem to be recieving the data that sends it to my email, is there anyway to fix this?
I have set the email to mine and tried with a domain email to.

Cixso
20-02-2009, 03:45 PM
Make a page called contactform.php

In it... add:


<form onKeyUp="highlight(event)" onClick="highlight(event)" name-"agreeform" onSubmit="return defaultagree(this)" action="sendmail.php" method="post" class="style1">
<p><span class="style2">
<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?>

<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />


<strong>Your Name: </strong><br />
<input type="text" name="visitor" size="35" />
</span></p>
<p><span class="style2"><strong>Your Email:</strong><br />
<input type="text" name="visitormail" size="35" />
<br />
<br />
<strong>Subject:</strong><br />
<select name="attn" size="1">
<option value=" Bug Reporting ">Bug Reporting </option>
<option value=" Career Options ">Link us </option>
<option value=" Abuse Report ">Abuse Report </option>
<option value=" Webmaster ">Webmaster </option>
<option value=" Other ">Other </option>
</select>
</span></p>
<p><span class="style2"><span class="style3">NOTE: If you are linking us, please provide your logo URL in the mail message! </span><br />
<br />
<strong>Mail Message:
</strong><br />
<textarea name="notes" rows="4" cols="40"></textarea>
</span></p>
<p>
<textarea name="textarea" cols="40" rows="3" wrap="VIRTUAL">By using this form you agree not to spam or abuse the purpose of this contact form. By submitting you agree that your IP is stored for security reasons and you agree we store your name and email. You agree to submit valid descriptions of your purpose for contacting us.</textarea>
<br />
<span class="style2">
<input name="agreecheck" type="checkbox" onClick="agreesubmit(this)">
I agree to the above terms</span><br>
<input type="submit" value="Send Mail" disabled>
<input type="reset" name="Reset" value="Reset">
</p>
</form>Then make a sendmail.php page and add:


<?php

$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$notes = $_POST['notes'];
$attn = $_POST['attn'];


if (eregi('http:', $notes)) {
die ("Do NOT try that! ! ");
}
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "- Invalid email. Enter a @domain email.\n";
$badinput = "Form was not submited.\n";
echo $badinput;
die ("Please go back and try again. ");
}

if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<b>Error:</b> Not all feilds where filled.\n";
die ("Please go back and correct this error.");
}

$todayis = date("l, F j, Y, g:i a") ;

$attn = $attn ;
$subject = $attn;

$notes = stripcslashes($notes);

$message = " $todayis [EST] \n
Attention: $attn \n
Message: $notes \n
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
";

$from = "From: $visitormail\r\n";


mail("[email protected]", $subject, $message, $from);

?>
<p align="left">
Date: <?php echo $todayis ?>
<br />
Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> )
<br />

Subject: <?php echo $attn ?>
<br />
Message:<br />
<?php $notesout = str_replace("\r", "<br/>", $notes);
echo $notesout; ?>
<br />
<?php>

****, hold on, the sendmail.php code is ******. Anybody correct it please?

efq
20-02-2009, 04:21 PM
Make a page called contactform.php

In it... add:


<form onKeyUp="highlight(event)" onClick="highlight(event)" name-"agreeform" onSubmit="return defaultagree(this)" action="sendmail.php" method="post" class="style1">
<p><span class="style2">
<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?>

<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />


<strong>Your Name: </strong><br />
<input type="text" name="visitor" size="35" />
</span></p>
<p><span class="style2"><strong>Your Email:</strong><br />
<input type="text" name="visitormail" size="35" />
<br />
<br />
<strong>Subject:</strong><br />
<select name="attn" size="1">
<option value=" Bug Reporting ">Bug Reporting </option>
<option value=" Career Options ">Link us </option>
<option value=" Abuse Report ">Abuse Report </option>
<option value=" Webmaster ">Webmaster </option>
<option value=" Other ">Other </option>
</select>
</span></p>
<p><span class="style2"><span class="style3">NOTE: If you are linking us, please provide your logo URL in the mail message! </span><br />
<br />
<strong>Mail Message:
</strong><br />
<textarea name="notes" rows="4" cols="40"></textarea>
</span></p>
<p>
<textarea name="textarea" cols="40" rows="3" wrap="VIRTUAL">By using this form you agree not to spam or abuse the purpose of this contact form. By submitting you agree that your IP is stored for security reasons and you agree we store your name and email. You agree to submit valid descriptions of your purpose for contacting us.</textarea>
<br />
<span class="style2">
<input name="agreecheck" type="checkbox" onClick="agreesubmit(this)">
I agree to the above terms</span><br>
<input type="submit" value="Send Mail" disabled>
<input type="reset" name="Reset" value="Reset">
</p>
</form>Then make a sendmail.php page and add:


<?php

$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$notes = $_POST['notes'];
$attn = $_POST['attn'];


if (eregi('http:', $notes)) {
die ("Do NOT try that! ! ");
}
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "- Invalid email. Enter a @domain email.\n";
$badinput = "Form was not submited.\n";
echo $badinput;
die ("Please go back and try again. ");
}

if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<b>Error:</b> Not all feilds where filled.\n";
die ("Please go back and correct this error.");
}

$todayis = date("l, F j, Y, g:i a") ;

$attn = $attn ;
$subject = $attn;

$notes = stripcslashes($notes);

$message = " $todayis [EST] \n
Attention: $attn \n
Message: $notes \n
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
";

$from = "From: $visitormail\r\n";


mail("[email protected]", $subject, $message, $from);

?>
<p align="left">
Date: <?php echo $todayis ?>
<br />
Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> )
<br />

Subject: <?php echo $attn ?>
<br />
Message:<br />
<?php $notesout = str_replace("\r", "<br/>", $notes);
echo $notesout; ?>
<br />
<?php>

****, hold on, the sendmail.php code is ******. Anybody correct it please?
Yeah the sendmail.php is broken, does anyone know how to fix it?

efq
21-02-2009, 09:55 AM
Does anyone have a sendmail.php?
I have managed to sort everything else, I just need that :P

I'll rep+

Cixso
21-02-2009, 10:09 AM
<?php

$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$notes = $_POST['notes'];
$attn = $_POST['attn'];


if (eregi('http:', $notes)) {
die ("Do NOT try that! ! ");
}
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "- Invalid email. Enter a @domain email.\n";
$badinput = "Form was not submited.\n";
echo $badinput;
die ("Please go back and try again. ");
}

if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<b>Error:</b> Not all feilds where filled.\n";
die ("Please go back and correct this error.");
}

$todayis = date("l, F j, Y, g:i a") ;

$attn = $attn ;
$subject = $attn;

$notes = stripcslashes($notes);

$message = " $todayis [EST] \n
Attention: $attn \n
Message: $notes \n
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
";

$from = "From: $visitormail\r\n";


mail("[email protected]", $subject, $message, $from);

?>

<p align="left">
Date: <?php echo $todayis ?>
<br />
Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> )
<br />

Subject: <?php echo $attn ?>
<br />
Message:<br />
<?php $notesout = str_replace("\r", "<br/>", $notes);
echo $notesout; ?>
<br />
<?php echo $ip ?>Try now.

Works, just tried - fixed it my self ;D

efq
21-02-2009, 10:19 AM
I've tried that and changed it to my email but it still isn't coming into my inbox.

Cixso
21-02-2009, 12:27 PM
I've tried that and changed it to my email but it still isn't coming into my inbox.

Make sure you check your spam inbox, also, what email are you sending it to?

efq
21-02-2009, 02:32 PM
My Yahoo Email and it isn't in the Spam.

Also, how can I make the email part and main content part optional?
I want them to have the choice to leave it blank and the main part and still submit not them having to put something in.

efq
22-02-2009, 09:01 AM
If its so hard to get it to send to a email is it possible for it to be sent to a file on the server?

Flash-Host
22-02-2009, 09:58 AM
PM And I Will Sort It

scottish
22-02-2009, 11:14 AM
http://w3schools.com/php/php_mail.asp

Robbie
22-02-2009, 12:40 PM
Page called contact.html or whatever you want



<html>
<head>
<title>I WANA SEND UR FORMZ.</title>
</head>

<body>
<form action="send.php" method="POST">
Name:<br>
<input type="text" name="name"><br><br>
Message:<br>
<textarea name="message">MESSAGE HERE</textarea><br><br>
<input type="submit" value="Send Message">
</form>
</body>
</html>
send.php


<?php

$name = $_POST["name"];
$message = $_POST["message"];

$write = fopen("formsubmissions.php", "a");
fwrite($write, "Name<br>$name<br><br>Message<br>$message<br><br>");
fclose($write);

echo('All done fnx');

?>

efq
22-02-2009, 01:13 PM
Page called contact.html or whatever you want



<html>
<head>
<title>I WANA SEND UR FORMZ.</title>
</head>

<body>
<form action="send.php" method="POST">
Name:<br>
<input type="text" name="name"><br><br>
Message:<br>
<textarea name="message">MESSAGE HERE</textarea><br><br>
<input type="submit" value="Send Message">
</form>
</body>
</html>
send.php


<?php

$name = $_POST["name"];
$message = $_POST["message"];

$write = fopen("formsubmissions.php", "a");
fwrite($write, "Name<br>$name<br><br>Message<br>$message<br><br>");
fclose($write);

echo('All done fnx');

?>


When I click send I get this...

$name

Message
$message

"); fclose($write); echo('All done fnx'); ?>

Dentafrice
22-02-2009, 06:33 PM
Try this, will send to e-mail:



<?php
$to_email = "[email protected]"; // this is the e-mail address the message will be sent to.
$subject_prefix = "Contact"; // Example: Will be [Contact] {name}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title>Send Message</title>
<style type="text/css">
body {
font-size: 14px;
font-family: Arial;
}
</style>
</head>
<body>

<?php
if($_GET["action"] == "send") {
$name = $_POST["name"];
$message = $_POST["message"];

if(empty($name) || empty($message)) {
?>
<fieldset>
<legend>ERROR</legend>
<p>
Both fields are required.
</p>
</fieldset>
<br /><br />
<?php
} else {
$message = nl2br($message); // turns textarea linebreaks into HTML pagebreaks.
$subject = "[{$subject_prefix}] {$name}"; // generates subject.
mail($to_email, $subject, $message); // sends the e-mail.
?>
<fieldset>
<legend>Sent</legend>
<p>
Your e-mail was sent successfully, thank you.
</p>
</fieldset>
<br /><br />
<?php
}
}
?>

<form name="send_data" method="post" action="?action=send">
<fieldset>
<legend>Send Data</legend>
<table>
<tr>
<td><label for="name"><strong>Name:</strong></label></td>
<td><input type="text" name="name" /></td>
</tr>

<tr>
<td><label for="data"><strong>Message:</strong></label></td>
<td><textarea cols="50" rows="5" name="message"></textarea></td>
</tr>

<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Send" /></td>
</tr>

</table>
</fieldset>
</form>
</body>
</html>

Want to hide these adverts? Register an account for free!