Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. if (isset($_POST['submit'])) {
  2. //process form
  3.  
  4. $name = mysql_prep($_POST["Name"]);
  5. //$name = (isset($_POST["Name"]) ?: "john"); //with escape strings
  6. $email_address = $_POST["Email"];
  7. $promo_email = $_POST["PromoEmail"];
  8.  
  9. //validations
  10.  
  11. $required_fields = array("Name", "Email");
  12. validate_presences($required_fields);
  13.  
  14. $field_with_max_lengths = array("Email" => 70);
  15. validate_max_lengths($field_with_max_lengths);
  16.  
  17. if (!empty($errors)) {
  18. redirect_to("http://www.example.com/coupon/coupon-error.php");
  19. }
  20.  
  21. $query = "INSERT INTO Coupon_Customers (";
  22. $query .= " Name, Email, PromoEmail ";
  23. $query .= ") VALUES (";
  24. $query .= " '{$name}', '{$email_address}', '{$promo_email}' ";
  25. $query .= ")";
  26. $result = mysqli_query($connection, $query);
  27.  
  28.  
  29. //query error?
  30.  
  31.  
  32. if ($result) {
  33. //SUCCESS
  34. //$_SESSION["message"] = "Record added.";
  35.  
  36.  
  37. $to = stripslashes($_POST["Email"]);
  38. $subject = "Your example's Coupon is Here!";
  39. $headers = "From: Here goes a title <no-reply@example.com>rn";
  40. $headers .= "Reply-To: info@example rn";
  41. $headers .= "MIME-Version: 1.0rn";
  42. $headers .= "Content-Type: text/html; charset=ISO-8859-1rn";
  43. $message = "<html><body>";
  44. $message .= "<table style='font-size:16px;width:100%;text-align:center;'>";
  45. $message .= "<tr>";
  46. $message .= "<td><img src='http://www.example/coupon/img/examples-logo.jpg' alt='Get $5 off on your next purchase of $25 or more' width='320' height='125' /></td>";
  47. $message .= "</tr>";
  48. $message .= "<tr>";
  49. $message .= "<td>Your example's Coupon is Here! Print out this email or present this coupon on your phone to your server and save!</td>";
  50. $message .= "</tr>";
  51. $message .= "<tr>";
  52. $message .= "<td style='font-size:13px;'>To unsubscribe, please email <a href='mailto:info@example'>info@example</a> with "Remove" in the subject line.</td>";
  53. $message .= "</tr>";
  54. $message .= "</table>";
  55. $message .= "</body></html>";
  56.  
  57. mail($to, $subject, $message, $headers);
  58.  
  59. redirect_to("http://www.example/coupon/coupon-thank-you.php");
  60.  
  61.  
  62. } else {
  63. //FAIL
  64. $_SESSION["message"] = "Unable to add record to database!";
  65. redirect_to("http://www.example/coupon/coupon.php");
  66. }
  67.  
  68. } else {
  69. //if GET request
  70. redirect_to("http://www.examples.com/coupon/coupon.php");
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement