- PHP Mail: Page content to mail
- // I am omitting elements to make this shorter
- <select name="Amount">
- <option value="1">1</option>
- <option value="2">2</option>
- <option value="3">3</option>
- </select>
- $price = 5;
- // I am omitting elements to make this shorter
- // here I do some math
- $Amount = $_GET['Amount'];
- // check value and select appropriate item
- if ($Amount== "1") {
- $extra = "1";
- }
- elseif ($Amount == "2") {
- $extra = "2";
- }
- elseif ($Amount == "3") {
- $extra = "3";
- // here is the order preview and this is what I need to email to myself
- // the customer should look this preview and then HIT a confirm buttom to get this sent
- <?php echo $Name;?><br>
- <?php echo $Address;?><br>
- <?php echo $E-mail;?><br>
- <?php echo $Phone;?><br>
- Your order: <?php echo $extra . " " . "products, for a total of" . " " . ($price * $extra); ?>
- <form method="get" id="order" action="order-info.php">
- <h1>Personal Info</h1>
- <p>name: <input name="name" type="text" /></p>
- <p>email: <input name="surname" type="text" /></p>
- <INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Continue">
- </form>
- <?php session_start(); ?>
- <?php
- // get info personal
- $Name = $_GET['name'];
- $Email = $_GET['email'];
- ?>
- // Now I echo the info
- <h2><?php echo $Name . " " . $Email ; ?><br></h2>
- <?php
- // here's where the magic is done thanks to Sheldon Ferns!
- $_SESSION['customerInfo']['name'] = $Name;
- $_SESSION['customerInfo']['email'] = $Email;
- ?>
- // having stored all the info in a session I proceed to send it to the email function. That weird name is because I read you should avoid naming your email process file with predictable names like mail.php, this increases protection against spammers.
- <form method ="POST" action = "xljkadf.php">
- <INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Confirm Order">
- <?php session_start();
- # Anti-header-injection - Use before mail()
- # By Victor Benincasa <vbenincasa(AT)gmail.com>
- foreach($_REQUEST as $fields => $value) if(eregi("TO:", $value) || eregi("CC:", $value) || eregi("CCO:", $value) || eregi("Content-Type", $value)) exit("ERROR: Code injection attempt denied! Please don't use the following sequences in your message: 'TO:', 'CC:', 'CCO:' or 'Content-Type'.");
- $headers = 'From: Your Site <noreply@yoursite.com>' . "n".
- // in the next line what I do is to send a BCC to me as I want the customer to get a copy of the order without knowing my address
- $headers .= 'Bcc: Your site <yourmail@xxxx.com>' . "rn";
- $mailBody = "Order details: n".
- "Name: ".$_SESSION['customerInfo']['name'] . "n".
- "Email: " .$_SESSION['customerInfo']['email'] . "n";
- // Next the mail function. The first arguments is the customer e-mail so he gets a copy of his order.
- mail($_SESSION['customerInfo']['Email'], "Order Info ", $mailBody, $headers);
- ?>
- // A redirect to a thank you page once the e-mail is sent.
- <script language="JavaScript" type="text/JavaScript">
- <!--
- window.location.href = "http://www.yoursite.com/thank-you.html";
- //-->
- </script>
- <?php
- session_start(); ?>
- //The php code you have already written.
- //Saving data in session
- <?php
- $_SESSION['customerInfo']['Name'] = $Name;
- $_SESSION['customerInfo']['Address'] = $Address;
- $_SESSION['customerInfo']['Email'] = $Email;
- $_SESSION['customerInfo']['Phone'] = $Phone;
- $_SESSION['customerInfo']['Extra'] = $Extra;
- ?>
- <?php
- session_start();
- $mailBody = "Order Info: n".
- "Name: ".$_SESSION['customerInfo']['Name'] . "n".
- "Address: " .$_SESSION['customerInfo']['Address'] . "n".
- "Email: " .$_SESSION['customerInfo']['Email'] . "n".
- "Phone: " .$_SESSION['customerInfo']['Email'] . "n".
- "Price: " .$_SESSION['customerInfo']['Price'] . "n".
- "Extra: " .$_SESSION['customerInfo']['Extra'] . "n";
- mail('your@mail.com', 'Order Information', $mailBody);
- ?>
- <?php ob_start(); ?>
- <?php echo $Name;?><br>
- <?php echo $Address;?><br>
- <?php echo $E-mail;?><br>
- <?php echo $Phone;?><br>
- Your order: <?php echo $extra . " " . "products, for a total of" . " " . ($price * $extra); ?>
- <?php $mailBody = ob_get_clean();
- mail('your@mail.com', 'Mail Subject', $mailBody);
- ?>