no idea where to start, email form

This is a discussion on "no idea where to start, email form" within the PHP Forum section. This forum, and the thread "no idea where to start, email form are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old May 22nd, 2007, 20:04
saltedm8's Avatar
SuperMember

SuperMember
Join Date: Nov 2005
Location: here
Age: 27
Posts: 1,519
Blog Entries: 2
Thanks: 1
Thanked 11 Times in 11 Posts
no idea where to start, email form

i am trying to create an email php script for this form, and thus far had no luck, would someone mind giving me a hand as i have no clue how to do it ( please change what you need to make it work ) - i also need it to go to a 'thank you page'

thank you

Code: Select all
deleted for space
Last Blog Entry: Strict and Transitional Doctype's (Sep 12th, 2008)

Last edited by saltedm8; May 23rd, 2007 at 09:37.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old May 22nd, 2007, 20:24
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: no idea where to start, email form

Here's a starter ...

1. Surround the table with tags
<form action=pyjamas.php method=POST>
and
</form>
so that the submit button knows what / where to submit

2. At the URL given for the action add something like this to your web site:
<?php
$em = "";
foreach (array_key($_POST) as $field) {
$em .= "$field: $_POST[$field]\n\n";
}
mail("george@whitehouse.com,"A user's input",$em);
?>
<html>
<body>
Thank you. We have emailed that to the president
</body>
</html>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old May 22nd, 2007, 21:10
saltedm8's Avatar
SuperMember

SuperMember
Join Date: Nov 2005
Location: here
Age: 27
Posts: 1,519
Blog Entries: 2
Thanks: 1
Thanked 11 Times in 11 Posts
Re: no idea where to start, email form

ok, i have a better idea, what is wrong with this

Code: Select all
 deleted for space
it goes with this

Code: Select all
deleted for space
i am getting this Parse error: syntax error, unexpected T_STRING in /home/xspeople/public_html/php/contact.php on line 6

thanks
Last Blog Entry: Strict and Transitional Doctype's (Sep 12th, 2008)

Last edited by saltedm8; May 23rd, 2007 at 09:15.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old May 23rd, 2007, 03:39
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: no idea where to start, email form

Quote:
Originally Posted by saltedm8 View Post
ok, i have a better idea, what is wrong with this

i am getting this Parse error: syntax error, unexpected T_STRING in /home/xspeople/public_html/php/contact.php on line 6

thanks
1. You are not allowed spaces in variable names (cause of error). I would sugget you change all field names to single words too - just take out the spaces!

2. You really should use arrays / loops for code like this - it is much longer than it needs to be and very hard to get every line right and longwinded to maintain.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old May 23rd, 2007, 08:33
saltedm8's Avatar
SuperMember

SuperMember
Join Date: Nov 2005
Location: here
Age: 27
Posts: 1,519
Blog Entries: 2
Thanks: 1
Thanked 11 Times in 11 Posts
Re: no idea where to start, email form

i dont have a clue about any php, i used a free script and added my fields. http://www.tele-pro.co.uk/scripts/contact_form/ , thanks, i will close the spaces
Last Blog Entry: Strict and Transitional Doctype's (Sep 12th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old May 23rd, 2007, 09:18
saltedm8's Avatar
SuperMember

SuperMember
Join Date: Nov 2005
Location: here
Age: 27
Posts: 1,519
Blog Entries: 2
Thanks: 1
Thanked 11 Times in 11 Posts
Re: no idea where to start, email form

ok, i now have

Code: Select all
 deleted for space
and

Code: Select all
 deleted for space
but it is taking me to my error page ( else value )

http://www.fmat.co.uk/email.html
Last Blog Entry: Strict and Transitional Doctype's (Sep 12th, 2008)

Last edited by saltedm8; May 24th, 2007 at 20:56.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old May 23rd, 2007, 17:43
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: no idea where to start, email form

Yes, because a form is regarded as "good" if a field called "EmailFrom" and "bad" if there is no data in such a field. Your form doesn't have a field of that name, so it can never be good as it stands ...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old May 23rd, 2007, 20:44
saltedm8's Avatar
SuperMember

SuperMember
Join Date: Nov 2005
Location: here
Age: 27
Posts: 1,519
Blog Entries: 2
Thanks: 1
Thanked 11 Times in 11 Posts
Re: no idea where to start, email form

ok, i have finally got it working ( or at least thats what its telling me - i have not recieved the emails yet ), will it display the sucess page and not send it ?
Last Blog Entry: Strict and Transitional Doctype's (Sep 12th, 2008)

Last edited by saltedm8; May 23rd, 2007 at 22:27.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old May 24th, 2007, 05:10
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: no idea where to start, email form

The "success" flag from the mail function only indicates that you have correctly passed the email to the first computer in the mail system - in other words that you have put the letter into the post box. It does not tell you whether it was correctly addressed (so will reach the intended recipient) nor if it will get caught on the way by a spam filter. It might even be that the local mail server isn't connected to the mail network - so that in effect you have posted your letter in a post box museum from which mail is never connected.

Try sending a simple email - just a one-liner in PHP with constant values - to yourself.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old May 24th, 2007, 05:27
saltedm8's Avatar
SuperMember

SuperMember
Join Date: Nov 2005
Location: here
Age: 27
Posts: 1,519
Blog Entries: 2
Thanks: 1
Thanked 11 Times in 11 Posts
Re: no idea where to start, email form

ok, recievied it this morning, - the only problem is that is sent me EVERY option, including the ones i did not choose, so i would have no clue as to which choices a client would have made, how do i get around that ?
Last Blog Entry: Strict and Transitional Doctype's (Sep 12th, 2008)

Last edited by saltedm8; May 24th, 2007 at 05:37.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old May 24th, 2007, 07:53
Reputable Member
Join Date: May 2006
Location: Northampton, UK
Posts: 399
Thanks: 0
Thanked 0 Times in 0 Posts
Re: no idea where to start, email form

Code: Select all
$Body .= "FreelanceDesignersSite:";
$Body .= $FreelanceDesignersSite;
$Body .= "\n";
$Body .= "DesignFirmsSite: ";
$Body .= $DesignFirmsSite;
$Body .= "\n";
$Body .= "WebsiteDesignDirectorySite: ";
$Body .= $WebsiteDesignDirectorySite;
$Body .= "\n";
$Body .= "WebsiteDesignDirectorySite: ";
$Body .= $WebsiteDesignDirectorySite;
$Body .= "\n";
$Body = "";
$Body .= "Other: ";
Ok, first of all the above code has variables defined within it for each of your options within your drop down menu. You dont need to do this.

When a user makes a selection from the menu, and clicks submit the value of the choice or "option value" is stored in the value of $_POST['referal']; this is because you have named the entire drop down menu as "referal".

So, simply email yourself the value of $_POST['referal'] and you will only be told the option they selected.

eg;
Code: Select all
$referal = $_POST['referal'];
The same holds true for radio buttons, in that they are placed into a group, and that group is assigned a value dependent upon thew users selection.

Checkbox's are a little different, they simply return 1 if they were selected, and 0 if they werent... however, a simply if else statement can change these binary values into the form of yes/no if you wish .... i dont bother 9 times out of 10.

hope this helped a little
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old May 24th, 2007, 12:43
saltedm8's Avatar
SuperMember

SuperMember
Join Date: Nov 2005
Location: here
Age: 27
Posts: 1,519
Blog Entries: 2
Thanks: 1
Thanked 11 Times in 11 Posts
Re: no idea where to start, email form

ok, thank you, i think i have got the $referal = $_POST['referal']; bit, but i am unsure on the radio buttons, i will give it a go and let you know

cheers
Last Blog Entry: Strict and Transitional Doctype's (Sep 12th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old May 24th, 2007, 20:54
saltedm8's Avatar
SuperMember

SuperMember
Join Date: Nov 2005
Location: here
Age: 27
Posts: 1,519
Blog Entries: 2
Thanks: 1
Thanked 11 Times in 11 Posts
Re: no idea where to start, email form

ok, i have managed a few things, this is what i have now

Code: Select all
<form method="POST" action="php/contact.php">
Fields marked (*) are required
  <table cellspacing="5" cellpadding="5" border="0">
    <tr>
      <td valign="top"><strong>*Full Name:</strong> </td>
      <td valign="top"><input type="text" name="FullName"  size="40" value="" />      </td>
    </tr>
    <tr>
      <td valign="top"><strong>*Email Address:</strong> </td>
      <td valign="top"><input type="text" name="EmailAddress" size="40" value="" />      </td>
    </tr>
    <tr>
      <td valign="top"><strong>Address:</strong> </td>
      <td valign="top"><input type="text" name="Address"  size="40" value="" />      </td>
    </tr>
    <tr>
      <td valign="top"><strong>city/town:</strong> </td>
      <td valign="top"><input type="text" name="citytown"  size="40" value="" />      </td>
    </tr>
    <tr>
      <td valign="top"><strong>Region:</strong> </td>
      <td valign="top"><input type="text" name="Region"  size="40" value="" />      </td>
    </tr>
    <tr>
      <td valign="top"><strong>Postcode/Zip:</strong> </td>
      <td valign="top"><input type="text" name="PostcodeZip"  size="40" value="" />      </td>
    </tr>
    <tr>
      <td valign="top"><strong>*Telephone:</strong> </td>
      <td valign="top"><input type="text" name="Telephone"  size="40" />      </td>
    </tr>
    <tr>
      <td valign="top"><strong> Current Website URL:</strong> ( if applicable ) </td>
      <td valign="top"><input type="text" name="CurrentWebsiteURL"  size="40" value="http://" />      </td>
    </tr>
    <tr>
      <td valign="top"><strong>Company Name:</strong> ( if applicable ) </td>
      <td valign="top"><input type="text" name="CompanyName"  size="40" value="" />      </td>
    </tr>
    <tr>
      <td valign="top"><strong>Referral:</strong> </td>
      <td valign="top"><select name="Referral" >
          <option value="Referral">How you Heard About Us </option>
          <option value="Referral">Client Referral </option>
          <option value="Referral">Print Add </option>
          <option value="Referral">Vehicle Add </option>
          <option value="Referral">Google Search </option>
          <option value="Referral">Yahoo Search </option>
          <option value="Referral">Other Search </option>
          <option value="Referral">Freelance Designers Site </option>
          <option value="Referral">Marketing Tool Site </option>
          <option value="Referral">Design Firms Site </option>
          <option value="Referral">Website Design Directory Site </option>
          <option value="Referral">Other</option>
        </select>      </td>
    </tr>
    <tr>
      <td valign="top"><strong>*Department:</strong> </td>
      <td valign="top"><select name="Department">
          <option value="Department">Sales Department </option>
          <option value="Department">Design Service </option>
          <option value="Department">Hosting Service </option>
          <option value="Department">Billing </option>
          <option value="Department">Tech Support </option>
          <option value=""></option>
        </select>      </td>
    </tr>
    <tr>
      <td valign="top"><strong>*Do You Currently Have Hosting:</strong></td>
      <td valign="top"><input type="radio" name="yes" value="DoYouCurrentlyHaveHosting " />Yes <br/>
        <input type="radio" name="no"  value="DoYouCurrentlyHaveHosting" />No<br/>      </td>
    </tr>
    <tr>
      <td valign="top"><strong>*Message:</strong>  ( please give us as much information as possible, as this will speed up the design process ) </td>
      <td valign="top"><textarea name="Message"  rows="6" cols="40"></textarea>      </td>
    </tr>
    <tr>
      <td colspan="2" align="center"><div align="right">
        <input name="submit" type="submit" value=" Submit Form " />
      </div></td>
    </tr>
  </table >
</form>
Code: Select all
<?php
// get posted data into local variables
$EmailFrom = admin@fmat.co.uk; 
$EmailTo = "my email";
$Subject = Trim(stripslashes($_POST['Subject'])); 
$FullName = Trim(stripslashes($_POST['FullName'])); 
$EmailAddress = Trim(stripslashes($_POST['EmailAddress'])); 
$Address = Trim(stripslashes($_POST['Address'])); 
$citytown = Trim(stripslashes($_POST['citytown'])); 
$Region = Trim(stripslashes($_POST['Region']));
$PostcodeZip = Trim(stripslashes($_POST['PostcodeZip'])); 
$Telephone = Trim(stripslashes($_POST['Telephone']));
$CurrentWebsiteURL = Trim(stripslashes($_POST['CurrentWebsiteURL'])); 
$CompanyName = Trim(stripslashes($_POST['CompanyName'])); 
$Referral = Trim(stripslashes($_POST['Referral']));  
$Department = Trim(stripslashes($_POST['Department']));  
$DoYouCurrentlyHaveHosting = Trim(stripslashes($_POST['DoYouCurrentlyHaveHosting'])); 
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}
// prepare email body text
$Body = "";
$Body .= "FullName: ";
$Body .= $FullName;
$Body .= "\n";
$Body .= "EmailAddress: ";
$Body .= $EmailAddress;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $Address;
$Body .= "\n";
$Body .= "citytown: ";
$Body .= $citytown;
$Body .= "\n";
$Body .= "Region: ";
$Body .= $Region;
$Body .= "\n";
$Body .= "PostcodeZip: ";
$Body .= $PostcodeZip;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $Telephone;
$Body .= "\n";
$Body .= "CurrentWebsiteURL: ";
$Body .= $CurrentWebsiteURL;
$Body .= "\n";
$Body .= "CompanyName: ";
$Body .= $CompanyName;
$Body .= "\n";
$Body .= "Referral: ";
$Body .= $Referral;
$Body .= "\n";
$Body .= "Department: ";
$Body .= $Department;
$Body .= "\n";
$Body .= "DoYouCurrentlyHaveHosting: ";
$Body .= $DoYouCurrentlyHaveHosting;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$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\">";
}
?>
and this is the result

FullName: *works*
EmailAddress: *works*
Address: xx *works*
citytown: Sittingbourne *works*
Region: xx *works*
PostcodeZip: xx *works*
Telephone: xx *works*
CurrentWebsiteURL: *works*
CompanyName: *works*
Referral: Referral **drop down not working**
Department: Department ** drop down not working**
DoYouCurrentlyHaveHosting: **radio buttons not working**
Message: this is a test of the mail form... *works*

3 problems, the drop down options not 'catching' the option chosen

and the radio buttons not working still

cheers
Last Blog Entry: Strict and Transitional Doctype's (Sep 12th, 2008)

Last edited by saltedm8; Aug 9th, 2008 at 15:22.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old May 26th, 2007, 02:34
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: no idea where to start, email form

On your radio buttons, you have your "name" and "value" fields reversed.

On your selects, you need to give a different value (which is the string you want back) for each value.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #15  
Old May 26th, 2007, 17:45
saltedm8's Avatar
SuperMember

SuperMember
Join Date: Nov 2005
Location: here
Age: 27
Posts: 1,519
Blog Entries: 2
Thanks: 1
Thanked 11 Times in 11 Posts
Re: no idea where to start, email form

horray, its working perfect, i can only thank you for your help. hope i can do the same for you one day
Last Blog Entry: Strict and Transitional Doctype's (Sep 12th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
email form

Thread Tools

Posting Rules