Destination address for a submit button?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hayward
Forum Newbie
Posts: 9
Joined: Thu Mar 31, 2011 8:07 am

Destination address for a submit button?

Post 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" />
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: Destination address for a submit button?

Post by fugix »

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?

Post 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! :)
eivind
Forum Commoner
Posts: 28
Joined: Tue Apr 19, 2011 7:57 am

Re: Destination address for a submit button?

Post 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>
hayward
Forum Newbie
Posts: 9
Joined: Thu Mar 31, 2011 8:07 am

Re: Destination address for a submit button?

Post 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!!!
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Destination address for a submit button?

Post 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.';
}
Post Reply