Page 1 of 1
Destination address for a submit button?
Posted: Wed Apr 20, 2011 10:17 am
by hayward
I have a submit button on a form which Id like the button to send the whole form to my email address this is my code any ideas?
<style type="text/css">
@media print {
input#btnPrint {
display: none;
}
}
</style>
<input type="button" id="btnPrint" onclick="window.print();" value="submit" />
Re: Destination address for a submit button?
Posted: Wed Apr 20, 2011 11:04 am
by fugix
you could add some code to send the variable to your email using the mail() function
Re: Destination address for a submit button?
Posted: Wed Apr 20, 2011 12:11 pm
by strafingmoose
In the action script:
Code: Select all
for each ($_POST as $variable) {
$emailBody = $emailBody.$variable.": ".$_POST[$variable]."\n"
}
Then send emailBody$ trough the mail() function.
The syntax might not be exactly OK, you're a programmer, hack at it!

Re: Destination address for a submit button?
Posted: Wed Apr 20, 2011 2:55 pm
by eivind
I would probably have something like this in action.php
Code: Select all
foreach ($_POST as $variable) {
$emailBody = $emailBody.$variable.": ".$_POST[$variable]."\n"
}
$to = 'yourmail@example.com';
$subject = 'the subject';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $emailBody, $headers);
and the following in the html file:
Code: Select all
<form action="action.php" method="POST">
[have form here]
<input type="submit" value="submit" />
</form>
Re: Destination address for a submit button?
Posted: Tue Apr 26, 2011 6:30 am
by hayward
oh im really no programer well not yet anyway this is the first time iv tried something like this, everything Iv tried hasn't really worked all I need is a button on a form called "RETURN TO US" as I want they're information to be emailed back to my email account, i also don't want the button to print out on the printed document, can someone simplify this for me please!!!
Re: Destination address for a submit button?
Posted: Tue Apr 26, 2011 6:42 am
by superdezign
It doesn't get any simpler. You remove the "window.print()" portion to stop it from printing and you use PHP to e-mail the POST data from the form. You could simplify the body of the e-mail to the entire $_POST array.
Code: Select all
if (!empty($_POST)) {
mail('me@example.com', 'Form submission', print_r($_POST, true));
echo 'E-mail sent.';
}