I'm having a terrible time trying to get my contact form to work. I have almost no php experience. I am trying to make this form e-mail to myself but have no idea what I am doing basically.
I need it to e-mail a copy of the form to my e-mail and also make sure the checkboxes show which boxes were clicked.
If anyone could help I would appreciate it.
Here is my html
<form name="htmlform" method="post" action="send_form_email.php">
<table width="561">
<tr>
<td width="212" align="right" valign="top">
<label for="name">*Name</label>
</td>
<td width="337" valign="top">
<input type="text" name="name" maxlength="150" size="50">
</td>
</tr>
<tr>
<td valign="top" align="right">
<label for="company">*Company</label>
</td>
<td width="337" valign="top">
<input type="text" name="name" maxlength="150" size="50">
</td>
</tr>
<tr>
<td valign="top" align="right">
<label for="telephone">Phone</label>
</td>
<td valign="top">
<input type="text" name="telephone" maxlength="150" size="50">
</td>
</tr>
<tr>
<td valign="top" align="right">
<label for="email">*Email Address</label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="180" size="50">
</td>
</tr>
<tr>
<td valign="top" align="right">
<label for="services">*Current Services<br />
(check all that apply)</label>
</td>
<td valign="top">
<input type="checkbox" name="services[]" value="none" /> None<br />
<input type="checkbox" name="services[]" value="coffee" /> Coffee<br />
<input type="checkbox" name="services[]" value="vending" /> Vending<br />
<input type="checkbox" name="services[]" value="watercoolers" /> Water Coolers<br />
<input type="checkbox" name="services[]" value="cafeteria" /> Cafeteria<br />
</td>
</tr>
<tr>
<td valign="top" align="right">
<label for="comments">*Comments</label>
</td>
<td valign="top">
<textarea name="comments" maxlength="1000" cols="40" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<center><input type="submit" value="Submit Form"></center>
</td>
</tr>
</table>
</form>
Here is my php.
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "michael@mrugenus.com";
$email_subject = "Contact form";
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Services: ".implode(",", $_POST['services'])."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
<center>
<img src="images/logo.png" />
<br>
<br>
Thank you for contacting us. We will be in touch.<br>
<br>
<a href="index.html">HOME</a></center>
<?php
}
?>
Ok Its fixed: PHP file:
Here is a sample code, which uses
SELECT
,CHECKBOX
,TEXTBOX
to get you going:The
email.php
: