Hi,
I'm a newbie in php.. having some trouble getting a simple contact form to work, could someone help and explain what the problem and a possible solution to this:
contact.html
<form method="post" id="customForm" action="contact.php">
<div>
<label for="name">Name</label>
<input id="name" name="name" type="text" />
<span id="nameInfo">What's your name?</span>
</div>
<div>
<label for="organisation">Organisation</label>
<input id="organisation" name="organisation" type="text" />
<span id="organisationInfo">Your organisation?</span>
</div>
<div>
<label for="email">E-mail</label>
<input id="email" name="email" type="text" />
<span id="emailInfo">Valid E-mail please!</span>
</div>
<div>
<label for="tel">Telephone</label>
<input id="tel" name="tel" type="text" />
<span id="telInfo">Contact telephone?</span>
</div>
<div>
<label for="message">Message</label>
<textarea id="message" name="message" cols="" rows=""></textarea>
</div>
<div>
<input id="send" name="send" type="submit" value="Send" />
</div>
</form>
contact.php
<?php
$to = "admin@website.com" ;
$from = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$organisation = $_REQUEST['organisation'] ;
$tel = $_REQUEST['tel'] ;
$headers = "From: $from";
$subject = "Contact form";
$fields = array();
$fields{"name"} = "name";
$fields{"email"} = "email";
$fields{"organisation"} = "organisation";
$fields{"tel"} = "tel";
$fields{"message"} = "message";
$body = "We have received the following information:\n\n"; foreach($fields as $a => $b)
{
$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);
}
$headers2 = "From: admin@website.com";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible. If you have any more questions, please consult our website at www.website.com";
if($from == '')
{
print "You have not entered an email, please go back and try again";
}
else
{
if($name == '')
{
print "You have not entered a name, please go back and try again";
}
else
{
if($organisation == '')
{
print "You have not entered a organisation, please go back and try again";
}
else
{
if($tel == '')
{
print "You have not entered a telephone, please go back and try again";
}
else
{
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{
print "Your message has been successfully sent!";
}
else
{
print "We encountered an error sending your mail, please notify admin@website.com";
}
}
}
?>
The form was working until I added the 'telephone' and 'organisation' boxes, have played around with it.. with no luck. Probably easy one for the more experience php users.
Many thanks in advance!