Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Web Design (WordPress, Joomla, etc.) PHP order form e-mail and redirect???

  • PHP order form e-mail and redirect???

    Posted by Harold Batista on November 27, 2010 at 12:02 am

    Hi All,

    I have this form that will collect data and e-mail it to a merchant. We have four payment methods they can choose: PayPal, Check, Wire Transfer, and Money Order. Right now, it sends an email that tells which one of these methods a user clicked on. Then it displays the message at the bottom that says Thank You for your order. Is there a way for the form to still send this information to the merchant’s e-mail, but if they choose the PayPal option, it would redirect them to our PayPal page instead of displaying the image at the bottom? I’m new to PHP and any help would be appreciated. I provided the code below.
    I imagine the logic goes something like:
    If PayPal (send e-mail, redirect:https://www.paypal.com/ourpage.html)
    If else (send e-mail)
    but im not great with the syntax yet.


    <?php
    if(isset($_POST['email'])) {

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "";
    $email_subject = "***(PRINT ORDER)***";

    function died($error) {
    // your error code can go here
    echo "We are very sorry, but there were error(s) found with the form you submitted. ";
    echo "These errors appear below.";
    echo $error."";
    echo "Please go back and fix these errors.";
    die();
    }

    // validation expected data exists
    if(!isset($_POST['email']) ||
    !isset($_POST['telephone']) ||
    !isset($_POST['address']) ||
    !isset($_POST['comments']) ||
    !isset($_POST['payment'])) {
    died('We are sorry, but there appears to be a problem with the form you submitted.');
    }

    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; // not required
    $comments = $_POST['address']; // required
    $comments = $_POST['comments']; // required
    $payment = $_POST['payment']; // required

    $error_message = "";
    $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
    if(!eregi($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.';
    }
    if(strlen($comments) < 2) {
    $error_message .= 'The Comments you entered do not appear to be valid.';
    }
    if(strlen($address) < 2) {
    $error_message .= 'The Address you entered do not appear to be valid.';
    }
    if(strlen($error_message) > 0) {
    died($error_message);
    }
    $email_message = "Form details below.\n\n";

    function clean_string($string) {
    $bad = array("content-type","bcc:","to:","cc:","href");
    return str_replace($bad,"",$string);
    }

    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Address: ".clean_string($address)."\n";
    $email_message .= "Comments: ".clean_string($comments)."\n";
    $email_message .= "Payment: ".clean_string($payment)."\n";

    // create email headers
    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers);
    ?>

    <!-- include your own success html here -->

    Thank you for your order. We will be in touch with you very soon.

    <?
    }
    ?>

    Abraham Chaffin replied 15 years, 5 months ago 2 Members · 1 Reply
  • 1 Reply
  • Abraham Chaffin

    December 2, 2010 at 5:20 pm

    Right after the line where you send the mail you can have an if then statement.


    @mail($email_to, $email_subject, $email_message, $headers);

    if($paypal)
    {
    $paypal_url="https://mypaypallocation.com/";
    header("Location: ".$paypal_url);exit;
    }

    Abraham

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy