Hello all...I am in a rut, confused.
I have created an html/php web form it works fine, the user enters the info and submits it to a confirmation page and then when the user clicks ok I need for the information to be sent to 2 email address' one it theres and the other is my own. I have read tutorials and I have 2 books, but I am confused. Can any one help me?

This is what I have in the confirmation page for when they click ok so it is sent to the email address...

<form method="POST"
action="confirmed.php">
<input type="hidden" name="mailto"
value="myemail@comp.com">

<h4>Please confirm the following information</h4>
Title: <?php echo $_POST["title"]; ?>
<br>
First Name: <?php echo $_POST["fname"]; ?>
<br>
MI: <?php echo $_POST["mname"]; ?>
<br>
Last Name: <?php echo $_POST["lname"]; ?>
<br>
...etc etc...

Thanks much!!

Recommended Answers

All 12 Replies

The function to email the information is
mail() google it for more..

also:
When you press the confirm button, are you posting the variables again?
Confirm button is on the intermediate page so if you press this the page which actually sends the email do not receive your variables from the form which is the first page.... get my point...?

I have that...

<?php
$to = "myemail_address";
$re = "Enquiry Form";
$msg = "Firstname: " $fname,
"MI: " $mname,
"Lastname: " $lname,
"Address: " $address,
"Apt: " $apt,
"City: " $city,
"State: " $state,
"Zip: " $zip,
"Email: "$email,
"Memo: "$memo,
mail($to,$re,$msg);
?>

But I am confused on where to put it...the first page is the form, when the user clicks submit the following page shows the output, like a confirmation to check their input...when the user clicks ok I need the info to be sent to the email address(s) and to a db(that I am working on).

Thanks

1st page is your normal form

2nd page can first display the contents by normal ECHO statement. Then it should also have a form surrounding the CONFIRM BUTTON... Something like this:

<form action="mail.php" action="POST">
<input type="hidden" name="to" value="<?=$_POST?>" >
<input type="hidden" name="msg" value="<?=$_POST?>" >
...
...
<input type="submit" value="Confirm" >
</form>

3rd Page should just take all the $_POST[] again and send them to mail() function.

Hope that helps?

Thanks for the help. I appreciate it...but now I get this error...


Warning: mail() [ function.mail ]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\PHP\e_mail.php on line 20
Cannot send e-mail.

Hmm...?

looks like the php is not configured to send mails
go to ur php.ini
and search for smtp and smtp_port

thank you w_3rabi!!! you were so right...it was def the smtp server!

can anyone help me with inserting info into a db??

what do u want to insert into db ??

Use this:

<?php

/* Database Configuration File
/ File name: db.php */

$host='';     //Host address
$user='';      //UserName
$passwd='';   //Password
$dbname='';   //Database Name

$con=mysql_connect($host,$user,$passwd);// or die("Cannot connect to database");

$db=mysql_select_db($dbname,$con);

?>

In your page where you put mail() function

include ('db.php');  //Database Config File
$sql = "insert into tablename values('value1','value2','value3') ";
$rs=  mysql_query($sql);

This is my code...I have it emailing the information to me after the hit 'Submit' and then I want it to also go to a db (code at the bottom)...what am I doing wrong?

Also, I have been trying and trying to be able to email to not only my email but to the users email...but how do I email to more than one person?!?

Thanks!!

<html>
<html>
<body bgcolor="#306EFF">
<head>
<title>Confirmation</title>
</head>
<body>
<form method="POST">
<!--action="Confirmed.php"-->
<font color="#FFE87C">
<h4>Please confirm the following information</h4>
</font color>
Title: <?php echo $_POST["title"]; ?>
<br>
First Name: <?php echo $_POST["fname"]; ?>
<br>
MI: <?php echo $_POST["mname"]; ?>
<br>
Last Name: <?php echo $_POST["lname"]; ?>
<br>
Address:<?php echo $_POST["address"]; ?>
<br>
Apt/Unit:<?php echo $_POST["apt"];?>
<br>
City:<?php echo $_POST["city"];?>
<br>
State:<?php echo $_POST["state"];?>
<br>
Zip:<?php echo $_POST["zip"];?>
<br>
Email:<?php echo $_POST["email"];?>
<br>
Memo:<?php echo $_POST["memo"];?>
<br>

<input type="submit" name="ok" value="Ok">
</form>
<?php
# Create an empty message variable.
$message="";
# The mail that we want to use to recevie the submitted information.
$to="email@comp.com";
# The E-Mail subject
$subject="Confirmation";
$ex=array();
$ex[]="submit"; # Where submit is the name of the submit button.
# iterate the $_POST array
foreach ($_POST as $key=>$value) {
if (!in_array($key, $ex)) {
$message.=$key.": " . $value."\n";
}
}
# Send message by e-mail.
$sm=mail($to, $subject, $message);
if (!$sm) {
print "Cannot send e-mail.";
}else{
print "E-Mail was sent.";
}

mysql_connect('localhost', 'root', "") or die ('Could not connect ' . mysql_error());
$query = mysql_query("INSERT INTO information VALUES ('title', 'fname', 'mname',
'lname', 'address', 'city', 'state', 'zip', 'email', 'memo')");
if (!$query) {
die('Data error ' . mysql_error());
}
echo 'Inserted successfully!';
mysql_close();
?>
</html>
</body>

use the mail function two times with different TO email field

Wow....I didn't even think of that! Thanks!!!

I did the mail() function again....but it just keeps sending emails to me and none to the user...

what did i do wrong?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.