PDA

View Full Version : Submit Button on a form



TuckJump
22-11-2008, 07:38 PM
Hi there i've got the following code

<input type="submit" name="button" id="button" value="Submit" />


what do i need to add to make it send to an e-mail address?

Moved by Meti (Forum Moderator) from Designing and Development: Please post in the correct forum next time, thanks ;).

Jackboy
22-11-2008, 10:54 PM
Hi there i've got the following code

<input type="submit" name="button" id="button" value="Submit" />
what do i need to add to make it send to an e-mail address?

Moved by Meti (Forum Moderator) from Designing and Development: Im a noob.

You need to point it to a page that handles the mail. Preferably the mail() function in php ;)

Look up mail();

Tylenol
23-11-2008, 06:22 AM
<input method="post" action="mailto:[email protected]" enctype="text/plain">

I "THINK" that will work. Unsure.

Trinity
23-11-2008, 06:25 AM
<input method="post" action="mailto:[email protected]" enctype="text/plain">

I "THINK" that will work. Unsure.

No, it won't.

Tylenol
23-11-2008, 06:26 AM
I appologize.

Calon
23-11-2008, 06:51 AM
<?php

if( ! $_POST[ 'submit' ] ) {
echo '<form action="" method="post">

Email to send to:<br /><input type="text" name="email" /><br />
Message:<br /><textarea rows="2" cols="20" name="message"></textarea><br />
<input type="submit" name="button" id="button" value="Submit" />

</form>';

} else {

$headers .= 'To: Me <[email protected]>' . "\r\n";
$headers .= 'From: Contact Email form thing! <[email protected]>' . "\r\n";

$subject = 'Couldn\'t be bothered to make another field, email from a contact form!';

$to = $_POST[ 'email' ];
$message = $_POST[ 'message' ];

mail($to, $subject, $message, $headers);

}
?>


That should work, change both of the headers to the emails that you wish to send to/from.

TuckJump
23-11-2008, 07:12 AM
Is there a more simpler one I'm using HTML really not PHP I've been shown a simpler one but can't remember it... But thanks for all the help!

HabbDance
24-11-2008, 08:12 PM
<?php

if( ! $_POST[ 'submit' ] ) {
echo '<form action="" method="post">

Email to send to:<br /><input type="text" name="email" /><br />
Message:<br /><textarea rows="2" cols="20" name="message"></textarea><br />
<input type="submit" name="button" id="button" value="Submit" />

</form>';

} else {

$headers .= 'To: Me <[email protected]>' . "\r\n";
$headers .= 'From: Contact Email form thing! <[email protected]>' . "\r\n";

$subject = 'Couldn\'t be bothered to make another field, email from a contact form!';

$to = $_POST[ 'email' ];
$message = $_POST[ 'message' ];

mail($to, $subject, $message, $headers);

}
?>
That should work, change both of the headers to the emails that you wish to send to/from.
How would you send that to more than 1 person?

Excellent2
24-11-2008, 08:28 PM
How would you send that to more than 1 person?I wouldn't advise making a bomber :P

Jam-ez
24-11-2008, 08:40 PM
Not the best at this but er;


<?php

if( ! $_POST[ 'submit' ] ) {
echo '<form action="" method="post">

Email to send to:<br /><input type="text" name="email" /><br />
Message:<br /><textarea rows="2" cols="20" name="message"></textarea><br />
<input type="submit" name="button" id="button" value="Submit" />

</form>';

} else {

$headers .= 'To: Me <[email protected]>' . "\r\n";
$headers .= 'From: Contact Email form thing! <[email protected]>' . "\r\n";

$subject = 'Couldn\'t be bothered to make another field, email from a contact form!';

$to = $_POST[ 'email' ];
$message = $_POST[ 'message' ];

mail($to, $subject, $message, $headers);
mail([email protected], $subject, $message, $headers);

}
?>

That would probably work, there's obviously other ways of doing it, it depends what exactly you want to do.

Or you could even add more form spaces;


<?php

if( ! $_POST[ 'submit' ] ) {
echo '<form action="" method="post">

Email to send to:<br /><input type="text" name="email" /><br />
Second Email to send to:<br /><input type="text" name ="email2" /><br />
Message:<br /><textarea rows="2" cols="20" name="message"></textarea><br />
<input type="submit" name="button" id="button" value="Submit" />

</form>';

} else {

$headers .= 'To: Me <[email protected]>' . "\r\n";
$headers .= 'From: Contact Email form thing! <[email protected]>' . "\r\n";

$subject = 'Couldn\'t be bothered to make another field, email from a contact form!';

$to = $_POST[ 'email' ];
$toalt = $_POST['email2'];
$message = $_POST[ 'message' ];

mail($to, $subject, $message, $headers);
mail($toalt, $subject, $message, $headers);

}
?>

Jxhn
24-11-2008, 08:55 PM
It would probably be best done by making an array of all the emails and then using a for loop.

HabbDance
24-11-2008, 09:29 PM
It would probably be best done by making an array of all the emails and then using a for loop.
Lol completely new to PHP and I'm trying to geuss. So I make the array, then I put the array name in the email place? < Complete guess so if I'm like way off, lol.

L?KE
24-11-2008, 09:36 PM
Nah you'd take the mail() function and shove it in a for loop for th eamount of emails.




// ... continued (assuming the email array is in place)

foreach($email as $email) {

mail($email, $subject, $message, $headers);

}

HabbDance
24-11-2008, 11:24 PM
I don't really get this but I'll try and piece a form together and I'll post it, and you guys can tell me how horribly wrong it is :D

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