I have a form that is a calculates an estimate for the user.

<form method="post" action="php/pricing.php">
<table id="pasa"><tr>
<td>Number of Pages?</td><td><textarea name="pages" value="" rows="1" cols="5"/>
</textarea></td></tr></table>
Can You Provide the following content?<br>
<table id="pasa"><tr><td></td><td>Yes</td><td>Some</td><td> No</td></tr>
<tr><td>Pictures</td><td><input type="radio" name="pictures" value="0"></td>
<td><input type="radio" name="pictures" value="25" checked></td>
<td><input type="radio" name="pictures" value="50"></td></tr>

<tr><td>Literature</td><td><input type="radio" name="literatures" value="0"></td>
<td><input type="radio" name="literatures" value="50" checked></td>
<td><input type="radio" name="literatures" value="100"></td></tr></table>
<br>

Would you like us to add or Graphically Enhance any of the following?<br>
<table id="pasas">
<tr><td>Pictures</td><td><input type="checkbox" name="picture" value="50" ></td></tr>
<tr><td>Page</td><td><input type="checkbox" name="page" value="50" ></td></tr>
<tr><td>Contact Form</td><td><input type="checkbox" name="contact" value="100" ></td></tr>
</table><br>
<input type="submit" name="go" value="Calculate" />
</form>

Pricing.php

<html>
<body>
<?php
$pages=$_POST['pages'];
$pictures=$_POST['pictures'];
$literatures=$_POST['literatures'];
$picture=$_POST['picture'];
$page=$_POST['page'];
$contact=$_POST['contact'];
$pagecost=$pages*50;
$picturecost=$pages*$pictures;
$literaturecost=$pages*$literatures;
$pictureenhance=$pages*$picture;
$pageenhance=$pages*$page;
$total=$pagecost+$picturecost+$literaturecost+$pictureenhance+$pageenhance+$contact;

echo "<table>";
echo "<tr><td>Total</td><td> $total</td></tr> ";
echo "<tr><td>Pages</td><td> $pages</td></tr>";
echo "<tr><td>Pictures</td><td> $pictures </td></tr>";
echo "<tr><td>Literatures</td><td> $literatures </td></tr>";
echo "<tr><td>Picture Enhance</td><td> $picture </td></tr>";
echo "<tr><td>Page Enhance</td><td> $page </td></tr>";
echo "<tr><td>Contact Form</td><td> $contact </td></tr>";
echo "<tr><td>Page Cost</td><td> $pagecost </td></tr>";
echo "<tr><td>Picture Cost</td><td> $picturecost </td></tr>";
echo "<tr><td>Literature Cost</td><td> $literaturecost </td></tr>";
echo "<tr><td>Picture Enhance Cost</td><td> $pictureenhance </td></tr>";
echo "<tr><td>Page Enhance Cost</td><td> $pageenhance </td></tr>";
echo "</table>";
?>
</body>
</html>

What I want to add is a Form in pricing.php asking the user to provide contact information. Upon submit I want the an email to be sent to me with the users contact information and the estimate information. I know the mail function is this. mail($recipient, $subject, $msg); How would I integrate all of this? I'm starting to feel like i bit off more than i can chew.. lol

Dani AI

Generated

As noted, a database is optional. Two reliable patterns are: (A) keep the calculated estimate and show a contact form on the same page (pass the estimate in hidden fields), or (B) save the estimate to the session and present a separate contact form page. Either way you collect contact info and then send a single email containing the estimate plus the contact fields.

Protect the inputs and handle missing checkboxes/radios. Use isset() and cast numeric inputs to integers, validate the email with filter_var() and escape output with htmlspecialchars() when printing back to the browser. Example of safe retrieval (server-side):

$pages = isset($_POST['pages']) ? (int) $_POST['pages'] : 0;
$pictureEnh = isset($_POST['picture']) ? (int) $_POST['picture'] : 0;
$userEmail = isset($_POST['email']) ? trim($_POST['email']) : '';
$validEmail = filter_var($userEmail, FILTER_VALIDATE_EMAIL);

Never trust raw POST values when building mail headers or message bodies. Strip CR/LF characters from any header-like fields to prevent header injection:

function clean_header($val) {
  return preg_replace("/[\r\n]+/", " ", trim($val));
}
$from = clean_header($name)." <".clean_header($validEmail).">";

For sending mail in production prefer a library like PHPMailer (SMTP/TLS support) over bare mail() for reliability and authentication; see the PHPMailer project for examples. Also consult the PHP docs for session usage if you choose the session approach, and validate all fields server-side even if you use HTML5 required on the form.

Finally: log or store each sent estimate (file or DB) if you need records, redirect after a successful POST to avoid duplicate sends on reload, and show a friendly thank-you page. Useful references: PHP filter_var() docs (validation), PHP session docs, the mail() docs, and the PHPMailer project on GitHub.

Recommended Answers

All 2 Replies

Now that you know the function, it should be easy. there are lots of example on how to use it. and maybe you can just put it after you insert the data to your DB.

Well the thing is i dont insert the estimates into a DB. Would using a DB be the only way?

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.