Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (isset($_POST['submit'])) {
- //process form
- $name = mysql_prep($_POST["Name"]);
- //$name = (isset($_POST["Name"]) ?: "john"); //with escape strings
- $email_address = $_POST["Email"];
- $promo_email = $_POST["PromoEmail"];
- //validations
- $required_fields = array("Name", "Email");
- validate_presences($required_fields);
- $field_with_max_lengths = array("Email" => 70);
- validate_max_lengths($field_with_max_lengths);
- if (!empty($errors)) {
- redirect_to("http://www.example.com/coupon/coupon-error.php");
- }
- $query = "INSERT INTO Coupon_Customers (";
- $query .= " Name, Email, PromoEmail ";
- $query .= ") VALUES (";
- $query .= " '{$name}', '{$email_address}', '{$promo_email}' ";
- $query .= ")";
- $result = mysqli_query($connection, $query);
- //query error?
- if ($result) {
- //SUCCESS
- //$_SESSION["message"] = "Record added.";
- $to = stripslashes($_POST["Email"]);
- $subject = "Your example's Coupon is Here!";
- $headers = "From: Here goes a title <no-reply@example.com>rn";
- $headers .= "Reply-To: info@example rn";
- $headers .= "MIME-Version: 1.0rn";
- $headers .= "Content-Type: text/html; charset=ISO-8859-1rn";
- $message = "<html><body>";
- $message .= "<table style='font-size:16px;width:100%;text-align:center;'>";
- $message .= "<tr>";
- $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>";
- $message .= "</tr>";
- $message .= "<tr>";
- $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>";
- $message .= "</tr>";
- $message .= "<tr>";
- $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>";
- $message .= "</tr>";
- $message .= "</table>";
- $message .= "</body></html>";
- mail($to, $subject, $message, $headers);
- redirect_to("http://www.example/coupon/coupon-thank-you.php");
- } else {
- //FAIL
- $_SESSION["message"] = "Unable to add record to database!";
- redirect_to("http://www.example/coupon/coupon.php");
- }
- } else {
- //if GET request
- redirect_to("http://www.examples.com/coupon/coupon.php");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement