FORUMS: list search recent posts

PHP order form e-mail and redirect???

COW Forums : Web Design

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Harold Batista
PHP order form e-mail and redirect???
on Nov 27, 2010 at 12:02:57 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:
If else (send e-mail)
but im not great with the syntax yet.

if(isset($_POST['email'])) {

$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.";

// 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) {
$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 -->

<p style="font-family:Arial,Helvetica,sans-serif;font-size:16px;">
Thank you for your order. We will be in touch with you very soon.



Return to posts index

Abraham Chaffin
Re: PHP order form e-mail and redirect???
on Dec 2, 2010 at 5:20:22 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);

header("Location: ".$paypal_url);exit;


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 All Rights Reserved