cancel
Showing results for 
Search instead for 
Did you mean: 

New to PHP

iendicott
Newbie
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.
<?php
$emailSubject = 'New Membership Details';
$webMaster ='webmaster@test123.com;

$emailField = $_POST['email'];

$body = <<EOD
Email Address: $email
EOD;
$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 http://www.tutvid.com/tutorials/dreamweaver/tutorials/phpFormHandler.php I get the jist but there is something I am not doing right.
Please Help.
1 REPLY
Superuser
Superuser
Posts: 9,759
Thanks: 1,146
Fixes: 62
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.

<?php
  $emailSubject = 'New Membership Details';
  $webMaster ='webmaster@my.email.address';
//   $emailField = $_POST['email']; // commented out and replaced by next line ...
  $emailField = 'me@my.email.address'; // ... for convenience in this test
  $body = <<<EOD
Email Address: $emailField<br>
Subject: $emailSubject<br>
EOD;
  $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.
David
Edit: I should have mentioned I set permissions on that file to 700. The directory I put it in has permissions 710.
David