Jump to content

Where is the submitted info sent? How can I send it to email?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
12 replies to this topic

#1
whaatup

whaatup

    Newbie

  • Members
  • Pip
  • 7 posts
When users enter their info and hit "submit", where is their information sent to?

<html>

</script>

<div align="center" style="text-indent: 0pt;"><img src="/page/-/files/header_form_title.jpg" border="0"></div>

<form action="volunteer.php" method="post" onSubmit="return checkform();" style="position:relative;">

<input class="header_input_fname" style="position:absolute; top:0; left:0;" name="firstname" id="fname" value="First Name"

onclick="if(this.value=='First Name'){this.value='';}">

<input class="header_input_lname" style="position:absolute; top:0; left:112px;" name="lastname" id="lname" value="Last

Name" onclick="if(this.value=='Last Name'){this.value='';}">

<input class="header_input_email" style="position:absolute; top:24px; left:0;" name="email" id="email" value="E-Mail"

onclick="if(this.value=='E-Mail'){this.value='';}">

<input class="header_input_zip" style="position:absolute; top:53px; left:0;" name="zip" id="zip" value="ZIP Code"

onclick="if(this.value=='ZIP Code'){this.value='';}">

<input type="image" src="/page/-/files/btn_signup.png" style="position:absolute; top:53px; left:110px;"

class="header_input_button"><br>

</form></div></div>

<div id="nav" style="background-image:url

(/page/smartproxy/BSD_EQROVgIKSFYJRlVGRQRHBAdQV1tAVgkdAVZf/FQRRUA/SA/AwxaUBA/CwRAVwIWOVYCHUBbVg);"><script

language="javascript">


How can I use this code to have it sent to an email?


Thank you

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
If you look at the HTML <form> element, you are sending POST data to volunteer.php. An example of how PHP would read the form data is like so:
<?php
  $fname = $_POST['firstname']; 
  $lname = $_POST['lastname'];
  $email = $_POST['email'];
  $zip = $_POST['zip']; 
  //Then you do something with it.
?>

Can you run PHP? Do you wish to have some example code to send an e-mail with it?
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
whaatup

whaatup

    Newbie

  • Members
  • Pip
  • 7 posts
I took this code from a website because I wanted something just like this on a page on my website. I would like to know how to have all the submitted info sent to an email, or somewhere that it can be logged and saved, like a database maybe?


Thanks

#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
You can do this with PHP, PERL or ASP but you will prefer it in PHP to keep it simple and replicate what the website is trying to do. I won't write anything too complex, but here's some PHP code to send you an e-mail. You will need to replace each "to" e-mail to yours, and the "from" e-mail in $headers to your site's name (ie: contact@foobar.com).

<?php

if(isset($_POST['fname']) && isset($_POST['lastname']) && isset($_POST['email']) && isset($_POST['zip'])) {
    //Grab data from HTML form inputs
    $fname = stripslashes($_POST['firstname']); 
    $lname = stripslashes($_POST['lastname']);
    $email = stripslashes($_POST['email']);
    $zip = stripslashes($_POST['zip']); 
} else {
    //A form wasn't filled in
    exit('One of the forms was blank, please go back and do it again.');
}

$to = 'you@youremail.com';
$subject = 'Someone has contacted you!';
$message = "Contact info: First name: $fname; Last name: $lname; e-mail: $email; ZIP code: $zip.";

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers, \r\n required by Windows
$headers .= 'To: Yourname <you@youremail.com>' . "\r\n";
$headers .= 'From: Yourname <contact@thissite.com>' . "\r\n";

// Mail it
if($mail = mail($to, $subject, $message, $headers)) {
   exit('Contact information successfully sent. Thank you');    
} else {
   exit('An error has occured, Please go back and try again.');    
}

?>

This is really a PHP question though, so you should ask on the PHP forum on here if you need further help. (if you want it to be in a database or whatnot).
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#5
whaatup

whaatup

    Newbie

  • Members
  • Pip
  • 7 posts
Thanks for your help I really appreciate it!

#6
whaatup

whaatup

    Newbie

  • Members
  • Pip
  • 7 posts
Do I put this code on a separate page from my code? Sorry but I'm a bit lost.


Thanks

#7
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
Yeah, you'd put it as for example "contact.php", and in your other web page you would use the form element as so:
<form action="contact.php" method="POST">

Just like in the code you originally showed us, this will tell HTML to send the form data (when they hit submit) to contact.php, the PHP code will accept the data and mail you with the form information. It's really a simple script.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#8
DarkLordofthePenguins

DarkLordofthePenguins

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 409 posts
Where the information is sent is specified by the action attribute of the <form> tag. If you want it to be mailed, you can set it to action="mailto:myaddress@mydomain".

#9
whaatup

whaatup

    Newbie

  • Members
  • Pip
  • 7 posts

DarkLordofthePenguins said:

Where the information is sent is specified by the action attribute of the <form> tag. If you want it to be mailed, you can set it to action="mailto:myaddress@mydomain".

All that would do is bring up your email program; it would open a new email to send with the set email already in the "Send to" field.

I need the script to automatically send the email from server side once they submit the info.

#10
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Then you will need some code on the server (PHP, ColdFusion, ASP, etc) to accept the form data and send the email.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#11
DarkLordofthePenguins

DarkLordofthePenguins

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 409 posts

whaatup said:

All that would do is bring up your email program; it would open a new email to send with the set email already in the "Send to" field.

I need the script to automatically send the email from server side once they submit the info.

That's odd. It worked fine for me. I think you may be thinking of mail links in achor tags, which are completely different. If you don't intend to read the email yourself and want it to be something the server processes, wouldn't it be easier to skip that step and do it the normal way (send it to a PHP script)?

#12
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
I'm helping him with the PHP script in PM, he can run PHP so it seems to be working.

@DarkLordofthePenguins: It depends on what the user has set as their default e-mail client, and their platform, so the mailto: tag generally isn't a good option. The PHP script hides the admin's e-mail as well, so it's best to let that handle itself.

It's a good JS option indeed, the OP just wasn't aware of what was sending the e-mail.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.