Can you help me getting this PHP code to work>?

Nik

New member
The first part is what goes in the html document as you can see.

<html>
<body>

<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail( "[email protected]", "Subject: $subject",
$message, "From: $email" );
echo "Thank you for using our mail form";
}
else
//if "email" is not filled out, display the form
{
echo "<form method='post' action='mailform.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='submit' />
</form>";
}
?>

</body>
</html>

The code below is the external part of the email

<?php
$to = "[email protected]";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "[email protected]";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

Obviously I aint good at this sort of thing yet I have only just started to learn PHP but can't get it to send mail which i need for the site i am building. When run it displays the very last tag in the html document.

I know php is server side I have downloaded and configured apache to run with php and downloaded php and configured it to work with apache so all is well there this works as well I ran a test on it.

It is just this code from w3schools that doesn't work. it displays the form also the end tag after the submit button but nothing happens when you click submit.
 
i've tried your code locally. It's running fine. I dont get what the problems are there in your server. I can give you two advises.

1) Debug using just a php file where there is a single hard coded mail function and figure out whether the problem is with mail configuration settings on your server.

2) View the page source to see why your form elements are not coming
 
Back
Top