Jump to content

Form help


hostfreak

Recommended Posts

[quote author=hostfreak link=topic=100381.msg396110#msg396110 date=1152761016]
I was wondering if it is possible to insert data from a form into my database and have the data be sent via email at that same time? I have no trouble doing either on there own, but combining the two is where I'm lost.
[/quote]

Yes, it possible to insert data into a database and email what it inserted within the same script. You might have an SQL statement:

[code]
<?php
$sql="INSERT INTO
        myTable
        (id, name, address, city, state, zip)
      VALUES(null, '".$name."', '".$address."',
        '".$city."', '".$state."', '".$zip."' )";

mysql_query($sql);
?>
[/code]

All you need is to send the mail (assuming your PHP has mailing enabled).

[code]
<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = "$name $address $city $state $zip";
$headers = 'From: webmaster@example.com' . "\r\n" .
  'Reply-To: webmaster@example.com' . "\r\n" .
  'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>
[/code]

[size=8pt]The above was taken and then edited from [url=http://us3.php.net/manual/en/function.mail.php]php.net[/url][/size].

The above should insert the data into the database and send the values to you.
Link to comment
Share on other sites

Sorry to bring this thread back up. Got another question. Instead of composing the email on the same page, is there anyway to include it from another file as I would if I were sending it on a contact form? Then reason is, I want it to display a confirmation. I know I could have it display a confirmation on that page but, it would also include the form they just filled out. I just want a confirmation of the information they just filled in for them to print.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.