Showing results for 
Search instead for 
Did you mean: 

New to PHP

Posts: 9
Registered: ‎19-10-2007

New to PHP

Hi all,
Looking at creating an online form so people can send me info via my website. I am trying to code a very simple page but have and error when trying to call it.
I am using dreamweaver that the form properties points to the PHP file which has the 755 permissions on the PHP file but when the PHP file is called I get a 405 Method Not Allowed, CGI was switched opn a while back, I suspect there is something wrong with my code so I have attached it below.
$emailSubject = 'New Membership Details';
$webMaster =';

$emailField = $_POST['email'];

$body = <<EOD
Email Address: $email
$headers = "From: $email\r\n";
$headers .= "Content-type: test/html\r\n";
$sucess = mail($webMaster, $emailSubject, $body, $headers);
echo "sucess";

The example was from this webpage I get the jist but there is something I am not doing right.
Please Help.
Resting Legend
Posts: 10,063
Thanks: 674
Fixes: 75
Registered: ‎06-04-2007

Re: New to PHP

There are a number of typos in your code, but it's easier to show you a version that works.

  $emailSubject = 'New Membership Details';
  $webMaster ='';
//   $emailField = $_POST['email']; // commented out and replaced by next line ...
  $emailField = ''; // ... for convenience in this test
  $body = <<<EOD
Email Address: $emailField<br>
Subject: $emailSubject<br>
  $headers = "From: $emailField\n";
  $headers .= "Content-type: text/html\n"; // you had 'test/html' here
  $success = mail($webMaster, $emailSubject, $body, $headers);
  echo $body,$success;

Note: relying on $email being set from the name of the form field will work at the moment because register_globals is on. However it will stop working when that is turned off. So best not to rely on it; set values you need from the $_POST global as done above in your original code. I made use of the extracted variable later.
Edit: I should have mentioned I set permissions on that file to 700. The directory I put it in has permissions 710.