Page 1 of 1

PHP submit form

Posted: Sun Feb 15, 2009 5:47 am
by jabbs72
Hi Guys,

First time here so I hope someone can help me, I have only just begun playing with php coding and have created a form, the following code seems to send the email ok but the result is the format after the code shown below.....I am not seeming to get any text that I have filled in in the form text fields when the email comes in.

Any help would be greatly appreciated.


Code:

Code: Select all

 
<?php
 
/* this is a comment = Subject and email variables */
 
    $emailSubject = 'Enquiry Form';
    $webMaster = 'gavinsmc@bigpond.net.au';
    
/* Gathering data variables */
    
    $nameField = $_POST['name'];
    $emailField = $_POST['email'];  
    $CompanyNameField = $_POST['CompanyName'];
    $arrivalDateField = $_POST['arrivalDate'];
    $homePhoneField = $_POST['homePhone'];
    $mobilePhoneField = $_POST['mobilePhone'];
    $faxField = $_POST['fax'];
    $countryField = $_POST['country'];
    $serviceField = $_POST['service'];
    $suburbsField = $_POST['suburbs'];
    $commentsField = $_POST['comments'];
    
    
    $body = <<<EOD
<br><hr><br>
Email: $email <br>
Name: $name <br>
Company Name: $Company name <br>
Arrival Date: $arrival date <br>
Home Phone: $home phone <br>
Mobile Phone: $mobile phone <br>
Fax: $fax <br>
County: $country <br>
Service: $service <br>
Suburbs: $suburbs <br>
Comments: $comments <br>
EOD;
 
    $headers = "From: $email\r\n";
    $headers .= "Content-type: text/html\r/n";
    $success = mail($webMaster, $emailSubject, $body, $headers);
    
    
/* Resuklts rendered as html */
    
    $theResults = <<<EOD
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>
 
<body>
<table width="522" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td>Thank you for your enquiry your email has been sent, we will be in contact very soon.</td>
  </tr>
</table>
</body>
</html>
EOD;
echo "$theResults";
 
?> 
 


the email result:

Email:
Name:
Company Name: name
Arrival Date: date
Home Phone: phone
Mobile Phone: phone
Fax:
County:
Service:
Suburbs:
Comments:

Re: PHP submit form

Posted: Sun Feb 15, 2009 6:08 am
by Benjamin
Please use the appropriate

Code: Select all

 [ /code] tags when posting code blocks in the forums.  Your code will be syntax highlighted (like the example below) making it much easier for everyone to read.  You will most likely receive more answers too!

Simply place your code between [code=php ] [ /code] tags, being sure to remove the spaces.  You can even start right now by editing your existing post!

If you are new to the forums, please be sure to read:

[list=1]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=8815]General Posting Guidelines[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/list]

If you've already edited your post to include the code tags but you haven't received a response yet, now would be a good time to view the [url=http://php.net/]php manual[/url] online.  You'll find code samples, detailed documentation, comments and more.

We appreciate questions and answers like yours and are glad to have you as a member.  Thank you for contributing to phpDN!

Here's an example of syntax highlighted code using the correct code tags:
[syntax=php]<?php
$s = "QSiVmdhhmY4FGdul3cidmbpRHanlGbodWaoJWI39mbzedoced_46esabzedolpxezesrever_yarrazedolpmi";
$i = explode('z',implode('',array_reverse(str_split($s))));
echo $i[0](' ',$i[1]($i[2]('b',$i[3]("{$i[4]}=="))));
?>[/syntax]

Re: PHP submit form

Posted: Sun Feb 15, 2009 7:47 am
by webnhance
I think I figured out your problem, you are calling the wrong variable names. You have all the variables with a "FIELD" at the end of them, yet when you go to get the data you forgot the correct variable names you created at the beginning of the form. $emailField = $_POST['email']; at the end you are just trying to call $email . Can you see the problem? And there is really no need to even create all those extra variables in the first place, because you can always access them using $_POST['email'], if you do need to access them inside an "echo" or something like that, just put squiggly brackets around them, and it will work inside pretty much anything. {$_POST['email']} Hope that's what your problem was.

Re: PHP submit form

Posted: Mon Feb 16, 2009 2:54 am
by jabbs72
Hi Webnhance,

Thanks for the response mate, I figured it out with your advise pointing me in the right directions.

Cheers :D