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" />
Destination address for a submit button?
Moderator: General Moderators
Re: Destination address for a submit button?
you could add some code to send the variable to your email using the mail() function
-
strafingmoose
- Forum Newbie
- Posts: 15
- Joined: Mon Apr 18, 2011 2:56 pm
Re: Destination address for a submit button?
In the action script:
Then send emailBody$ trough the mail() function.
The syntax might not be exactly OK, you're a programmer, hack at it!
Code: Select all
for each ($_POST as $variable) {
$emailBody = $emailBody.$variable.": ".$_POST[$variable]."\n"
}The syntax might not be exactly OK, you're a programmer, hack at it!
Re: Destination address for a submit button?
I would probably have something like this in action.php
and the following in the html file:
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);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?
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!!!
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Re: Destination address for a submit button?
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.';
}