PHP Script -- Return E-mail...

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
fr0z3ng33k
Forum Members
Forum Members
Posts: 59
Joined: Thu Mar 03, 2011 4:47 pm

PHP Script -- Return E-mail...

Post by fr0z3ng33k »

Three Questions:
1) Where do I upload my .php script so that when you click the "Submit" button on my contact us page the script returns the data to my e-mail address?

2) Once "Submit" is selected how do I get it to direct you to this page "http://www.mysitename.com/index.php?page=thank-you" Basically with the code I supplied how do I write this in?
I see the sections on where I am to write this all the way at the bottom of the code, just no idea how to put it in there correctly.

3) I have code for a drop down box with many options to choose from, if I add that code into the html portion how do I add it to the php script so it's recognized?

Below is the code, it wouldn't let me upload the file. So I had to copy / paste it.

Also once this gets running perfectly I will supply everything html / php for those who need this same Submit Button feature.

Code: Select all

<?php

// get posted data into local variables
$EmailFrom = "info@mysitename.com";
$EmailTo = "me@mysitename.com";
$Subject = "Thank you for your interest";
$FirstName = Trim(stripslashes($_POST['FirstName'])); 
$LastName = Trim(stripslashes($_POST['LastName'])); 
$Title = Trim(stripslashes($_POST['Title'])); 
$Company = Trim(stripslashes($_POST['Company'])); 
$Email = Trim(stripslashes($_POST['Email'])); 
$Phone = Trim(stripslashes($_POST['Phone'])); 
$Address = Trim(stripslashes($_POST['Address'])); 
$City = Trim(stripslashes($_POST['City'])); 
$State/Province = Trim(stripslashes($_POST['State/Province'])); 
$Zip = Trim(stripslashes($_POST['Zip'])); 
$Comments = Trim(stripslashes($_POST['Comments'])); 

// validation
$validationOK=true;
if (Trim($FirstName)=="") $validationOK=true;
if (Trim($LastName)=="") $validationOK=true;
if (Trim($Title)=="") $validationOK=true;
if (Trim($Company)=="") $validationOK=true;
if (Trim($Email)=="") $validationOK=false;
if (Trim($Phone)=="") $validationOK=true;
if (!is_numeric($Phone)) $validationOK=true;
if (Trim($Address)=="") $validationOK=true;
if (Trim($City)=="") $validationOK=true;
if (Trim($State/Province)=="") $validationOK=true;
if (Trim($Zip)=="") $validationOK=true;
if (!is_numeric($Zip)) $validationOK=true;
if (Trim($Comments)=="") $validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "FirstName: ";
$Body .= $FirstName;
$Body .= "\n";
$Body .= "LastName: ";
$Body .= $LastName;
$Body .= "\n";
$Body .= "Title: ";
$Body .= $Title;
$Body .= "\n";
$Body .= "Company: ";
$Body .= $Company;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $Phone;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $Address;
$Body .= "\n";
$Body .= "City: ";
$Body .= $City;
$Body .= "\n";
$Body .= "State/Province: ";
$Body .= $State/Province;
$Body .= "\n";
$Body .= "Zip: ";
$Body .= $Zip;
$Body .= "\n";
$Body .= "Comments: ";
$Body .= $Comments;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
Last edited by fr0z3ng33k on Tue May 24, 2011 2:45 pm, edited 1 time in total.
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

Re: PHP Script -- Return E-mail...

Post by Nullig »

Just use the FormBuilder module.

Nullig
fr0z3ng33k
Forum Members
Forum Members
Posts: 59
Joined: Thu Mar 03, 2011 4:47 pm

Re: PHP Script -- Return E-mail...

Post by fr0z3ng33k »

I was I just would rather code this on my own since I can edit the sizes of the text boxes and edit the coding myself for practice. Thanks though, plus I struggle with form builder on certain things.
Jos
Support Guru
Support Guru
Posts: 4020
Joined: Wed Sep 05, 2007 8:03 pm

Re: PHP Script -- Return E-mail...

Post by Jos »

You can create a UDT to build your own form. Note that you have to leave the php start and closing tags out of your code.

Here's some example code for a simple form with just a submit button:

Code: Select all

if ( $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['MySubmit']))
{      
   // do your php stuff and mail function

   echo 'Form is submitted';

}
else
{
   echo '<form action="" method="post">';
   echo '<input type="submit" name="MySubmit" value="Submit" />';
   echo '</form>';
}
fr0z3ng33k
Forum Members
Forum Members
Posts: 59
Joined: Thu Mar 03, 2011 4:47 pm

Re: PHP Script -- Return E-mail...

Post by fr0z3ng33k »

Jos wrote:You can create a UDT to build your own form. Note that you have to leave the php start and closing tags out of your code.
I guess I should have mentioned that I am a newb and I had failed a creating a form using Formbuilder already (just didn't look like the one I already have that I'm replacing).

Really I just want to know where to put that code to take the person to the next page once Submit is clicked and where to attach the php file on the server. If someone knows the dropdown box answer in php even better.

Thank you though for the info, I'm sure if I wasn't so new to this I'd be better off with that information.
Jos
Support Guru
Support Guru
Posts: 4020
Joined: Wed Sep 05, 2007 8:03 pm

Re: PHP Script -- Return E-mail...

Post by Jos »

UDT = User Defined Tag, check admin menu Extensions. A UDT in itself has nothing to do with Formbuilder.
fr0z3ng33k wrote:I was I just would rather code this on my own
I don't know if I understood you correctly, but if you want to code the form yourself, but you don't have any basic understanding of php, I don't think you will get any other answer than to use Formbuilder.

For the redirect maybe the {redirect_page} tag may be of use to you. Check Extensions -> Tags for the help on this tag.
fr0z3ng33k
Forum Members
Forum Members
Posts: 59
Joined: Thu Mar 03, 2011 4:47 pm

Re: PHP Script -- Return E-mail...

Post by fr0z3ng33k »

Jos wrote:UDT = User Defined Tag, check admin menu Extensions. A UDT in itself has nothing to do with Formbuilder.
fr0z3ng33k wrote:I was I just would rather code this on my own
I don't know if I understood you correctly, but if you want to code the form yourself, but you don't have any basic understanding of php, I don't think you will get any other answer than to use Formbuilder.

For the redirect maybe the {redirect_page} tag may be of use to you. Check Extensions -> Tags for the help on this tag.
Thanks I wasn't sure what the UDT mean't. I'm looking at the extensions / tags to get a better understanding of this stuff.

What I did was find a site that allows you to pick what you want in a form and it generates the html code for the form and the php script for your server. I am now just editing that code to add a drop down with 24 choices and getting it to redirect to another page. I apologize if this isn't clear, I am new to all of this and I learn / read every day to get better.

Formbuilder was awesome, don't get me wrong I like it. I just couldn't align other text on the left of the form easily, and the text boxes were all aligned but 2 and I couldn't figure out how to even those out and the submit button wouldn't work for me. Thus the reason for me trying to code this without the use of the wonderful CMS modules.
Post Reply

Return to “The Lounge”