PHP form

Status
Not open for further replies.

murdocsvan

Web Programmer
Messages
896
Location
Surrey, UK
Recently i've been really getting into PHP and have been using W3Schools Online Web Tutorials as tutorials. Now im just experimenting a bit and combining what i know. JUST FOR A LAUGH(not a spambomb) i've made a form which can send out an email to a specified email address. I've also made it so that you can choose what your email address , and you can choose how many it sends.

I've now tried putting in a checkbox which allows the person doing it to randomise the email address it sends from. Howvee rim having loads of trouble trying to get this to work.

This is the HTML form:

Code:
<html>
<body>
<head>
<meta name="robots" content="noindex, nofollow" />
<meta name="robots" content="noarchive" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>:.:PHP Practise Work:.:</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>

<form action="form_result.php" method="post">
Email of recipiant: <input type="text" name="email" /><br />
Email of sender: <input type="text" name="semail" />
<input type="checkbox" name="random" value="random">Random?<br />

Number of emails to send: <input type="text" name="amount" /><br />
<input type="submit" value="Send" />
<input type="reset" value="Reset" />
</form>

</body>
</html>

And this is the form that the data gets sent to, using $_POST:

Code:
<?php

function = randomize()
	{
	if ($_POST["random"]="random")
		return rand(1,8) . "@" . rand(1,5) . ".com";
	else 
		return $_POST["semail"];
	}

$val=1;
while($val<=$_POST["amount"])
	{
	$to = $_POST["email"];
	$subject = "LOL";
	$message = "Ka-Pwned!!";
	$from = randomize();
	$headers = "From: $from";
	mail($to,$subject,$message,$headers);
	$val++;
	}
	
	
echo "Emails sent!";
	
?>

Whenever i've tried it, it submits, but then says it has a problem parsing on the 3rd line.
 
Code:
if ($_POST['random'] == true)

Should be like this.

HTML Forms Input Type Checkbox

read value

Here are the attributes to this input type

input * - tells the browser that this is part of the form

type * - tells the browser what input type it is

name * - when the form is submitted, this is the header the information in this field will go under

value * - this is what it the browser sends if that box is checked (can be anything)

checked - if this is included in the tag, when the page loads up it will already be checked
 

Defining a value is optional.

PHP:
<?php

$check = $_POST['checkbox'];

if ($check == true) { echo 'true<br />'; }
if ($check == 'on') { echo 'on<br />'; }
if ($check) { echo '$check<br />'; }

echo '<br /><br /><form action="checkbox.php" method="post">
<input type="checkbox" name="checkbox" /><input type="submit" name="submit" value="submit" />
</form>';

?>

In this script, all of the if's work. If you give the checkbox a value, then you need to change == 'on' to the value.

In any case though, he only had one = when he should have had ==.
 
Status
Not open for further replies.
Back
Top Bottom