PDA

View Full Version : PHP e mail form


eason1
12-28-2011, 06:47 PM
I have been trying to create a simple e mail contact form in CS3 using a form I created in html which then should run a php form. However, when I preview the form and click on submit it tries to open the php file instead of running it. I get a pop up box asking whether I want to save it or open the php file. I am, thinking I have made a simple ommision or error.

Can anyone help. The php code is underneath this message.

Thanks

<?php # fourm.php


// Check if the form has been submitted:
if (isset($_POST['submitted'])) {
$errors = array(); // Initialize an error array.

// Check for a first name:
if (empty($_POST['first_name'])) {
$errors[] = 'You forgot to enter your first name.';
}

// Check for a last name:
if (empty($_POST['last_name'])) {
$errors[] = 'You forgot to enter your last name.';
}

// Check for an email address:
if (empty($_POST['email address'])) {
$errors[] = 'You forgot to enter your email address.';
}
// Check for an Telephone Number:
if (empty($_POST['Telephone Number'])) {
$errors[] = 'You forgot to enter your email address.';
}
// Check for comments:
if (empty($_POST['Comments'])) {
$errors[] = 'You forgot to leave any feedback.';
}

if (empty($errors)) { // If everything's OK.

/* Gathering Data Variables */
$firstname = $_POST['first_name'];
$lastname = $_POST['last_name'];
$email = $_POST['email'];
$Telephone Number = $_POST['Telephone Number'];
$Comments= $_POST['Comments'];


// Print a message:
echo "<h1>Thank you!</h1>
<p>Thank you for your ticket request</p>";

//Send Email:


/* Subject and Email Variables */
$sendToAddress = "season@all-saints.bardaglea.org.uk";
$emailSubject = "Feedback From Website";

$body = "Someone has submitted feedback on your website.\n\nFirst Name: $firstname\nLast Name: $lastname\nEmail: $email\nFeedback: $feedback";

$body = wordwrap($body, 70);


$headers = "From: $firstname $lastname <$email>\r\n";


$success = mail($sendToAddress, $emailSubject, $body, $headers);










exit();

} else { // Report the errors.

echo '<h1>Error!</h1>
<p class="error">The following error(s) occurred:<br />';
foreach ($errors as $msg) { // Print each error.
echo " - $msg<br />\n";
}
echo '</p><p>Please try again.</p><p><br /></p>';

} // End of if (empty($errors)) IF.

} // End of the main Submit conditional.
?>

<form name="contactform" method="post" action="SSform.php">
<table width="450px">
<tr>
<td valign="top">
<label for="first_name">First Name *</label>
</td>
<td valign="top">
<input type="text" name="first_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top"">
<label for="last_name">Last Name *</label>
</td>
<td valign="top">
<input type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="email">Email Address *</label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="80" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="telephone">Telephone Number</label>
</td>
<td valign="top">
<input type="text" name="telephone" maxlength="30" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="comments">Comments *</label>
</td>
<td valign="top">
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit"></td>
</tr>
</table>
</form>

edbr
12-29-2011, 01:27 AM
your server(all-saints.bardaglea.org.uk) shows
server: Microsoft-IIS/7.0
x-powered-by: ASP.NET
it is not enabled for php

eason1
12-29-2011, 11:17 AM
Many thanks.
So if I find a host that's pho enabled this may solve the problem?
Thanks again.

domedia
12-29-2011, 01:43 PM
Yes, or use a server side technology that is supported by your current host.

edbr
12-30-2011, 11:02 PM
you could google for ASP form to mail , try hotscripts or use a perl script. Normally your host will have one on the server