Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 22nd, 2012  |  syntax: None  |  size: 4.26 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. PHP Mail: Page content to mail
  2. // I am omitting elements to make this shorter    
  3. <select name="Amount">
  4.       <option value="1">1</option>
  5.       <option value="2">2</option>
  6.       <option value="3">3</option>
  7.      </select>
  8.        
  9. $price = 5;  
  10.  
  11.     // I am omitting elements to make this shorter
  12.     // here I do some math    
  13.     $Amount = $_GET['Amount'];
  14.         // check value and select appropriate item
  15.         if ($Amount== "1") {
  16.             $extra = "1";
  17.             }
  18.         elseif ($Amount == "2") {
  19.             $extra = "2";
  20.             }
  21.         elseif ($Amount == "3") {
  22.             $extra = "3";
  23.  
  24.  
  25. // here is the order preview and this is what I need to email to myself
  26. // the customer should look this preview and then HIT a confirm buttom to get this sent
  27.  
  28. <?php echo $Name;?><br>
  29. <?php echo $Address;?><br>
  30. <?php echo $E-mail;?><br>
  31. <?php echo $Phone;?><br>
  32. Your order: <?php echo $extra . " " . "products, for a total of" . " " . ($price * $extra); ?>
  33.        
  34. <form method="get" id="order" action="order-info.php">
  35. <h1>Personal Info</h1>
  36. <p>name: <input name="name" type="text" /></p>
  37. <p>email: <input name="surname" type="text" /></p>
  38. <INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Continue">
  39. </form>
  40.        
  41. <?php session_start(); ?>
  42. <?php
  43. // get info personal
  44. $Name = $_GET['name'];
  45. $Email = $_GET['email'];
  46. ?>
  47. // Now I echo the info
  48. <h2><?php echo $Name . " " . $Email ; ?><br></h2>
  49. <?php
  50.   // here's where the magic is done thanks to Sheldon Ferns!
  51.   $_SESSION['customerInfo']['name'] = $Name;
  52.   $_SESSION['customerInfo']['email'] = $Email;
  53.  
  54. ?>
  55. // 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.
  56. <form  method ="POST" action = "xljkadf.php">
  57. <INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Confirm Order">
  58.        
  59. <?php  session_start();
  60.  # Anti-header-injection - Use before mail()
  61. # By Victor Benincasa <vbenincasa(AT)gmail.com>
  62. 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'.");
  63.  
  64.   $headers = 'From: Your Site <noreply@yoursite.com>' . "n".
  65. // 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  
  66. $headers .= 'Bcc: Your site <yourmail@xxxx.com>' . "rn";
  67.  
  68.  
  69.  
  70.   $mailBody = "Order details: n".
  71.                 "Name: ".$_SESSION['customerInfo']['name'] . "n".
  72.                 "Email: " .$_SESSION['customerInfo']['email'] . "n";
  73.  
  74.  
  75.  
  76.  
  77. // Next the mail function. The first arguments is the customer e-mail so he gets a copy of his order.
  78.    mail($_SESSION['customerInfo']['Email'], "Order Info ", $mailBody, $headers);
  79.  
  80.    ?>
  81.  // A redirect to a thank you page once the e-mail is sent.
  82. <script language="JavaScript" type="text/JavaScript">
  83. <!--
  84. window.location.href = "http://www.yoursite.com/thank-you.html";
  85. //-->
  86. </script>
  87.        
  88. <?php
  89.   session_start(); ?>
  90.   //The php code you have already written.
  91.  
  92.   //Saving data in session
  93.   <?php
  94.   $_SESSION['customerInfo']['Name'] = $Name;
  95.   $_SESSION['customerInfo']['Address'] = $Address;
  96.   $_SESSION['customerInfo']['Email'] = $Email;
  97.   $_SESSION['customerInfo']['Phone'] = $Phone;
  98.   $_SESSION['customerInfo']['Extra'] = $Extra;
  99. ?>
  100.        
  101. <?php
  102.   session_start();
  103.   $mailBody = "Order Info: n".
  104.               "Name: ".$_SESSION['customerInfo']['Name'] . "n".
  105.               "Address: " .$_SESSION['customerInfo']['Address'] . "n".
  106.               "Email: " .$_SESSION['customerInfo']['Email'] . "n".
  107.               "Phone: " .$_SESSION['customerInfo']['Email'] . "n".
  108.               "Price: " .$_SESSION['customerInfo']['Price'] . "n".
  109.               "Extra: " .$_SESSION['customerInfo']['Extra'] . "n";
  110.  
  111.    mail('your@mail.com', 'Order Information', $mailBody);
  112.  
  113. ?>
  114.        
  115. <?php ob_start(); ?>
  116. <?php echo $Name;?><br>
  117. <?php echo $Address;?><br>
  118. <?php echo $E-mail;?><br>
  119. <?php echo $Phone;?><br>
  120. Your order: <?php echo $extra . " " . "products, for a total of" . " " . ($price * $extra); ?>
  121. <?php $mailBody = ob_get_clean();
  122.  
  123. mail('your@mail.com', 'Mail Subject', $mailBody);
  124.  
  125. ?>