html form to email by php script help

I’m trying to make a form where the user or client fills it out and then hits submit which would then send it to the
receiving email address provided. However, every time I hit submit or try it out, it seems like it would work, and then I check my inbox where there is no new message. Any help on making this possible would be great. I will include both the HTML and PHP code below that I have been working with. The HTML i worked from scratch,however, I’m new to php and cannot seem to make the magic happen. If you want, you may email me your thoughts at [email protected], which would be easier for me, or you could simply post here and I will check it when i can. Thank you for your help!

[php]<?php
if($_POST[‘submit’] == “Submit”);

$Client Name = htmlspecialchars ($_POST[‘name’]);
$Client phone = htmlspecialchars ($_POST[‘phone’]);
$Client Email = htmlspecialchars ($_POST[‘email’]);
$Type of Computer = htmlspecialchars ($_POST[‘type of computer’]);
$Brand = htmlspecialchars ($_POST[‘brand’]);
$Model = htmlspecialchars ($_POST[‘model’]);
$Operating Sytem = htmlspecialchars ($_POST[‘OS’]);
$Errors and Issues = htmlspecialchars ($_POST[‘Errors’]);
$formcontent = “From: $Client Name \n Phone: $Client phone \n Email: $Client email \n Computer: $Type of Computer \n Brand: $Brand \n Model: $Model \n OS: $Operating System \n
Errors: $Errors and Issues \n;
$recipient = "[email protected]”;
$subject = “Client Form”;
$mailheader = “From: $Client email \r\n”;

$email_from = ‘[email protected]’;
$email_subject = “Client Form”;
$to = "[email protected]";
$headers = “From: $Client email_from \r\n”;
mail($to,$email_subject);

mail($recipient, $subject, $formcontent, $mailheader);

?>[/php]

[code]

Fields with * are required.

Client Information
Name: *
Phone: *

(555) 555-0000

E-mail Address: *
Computer Information

Type of Computer: * Desktop/Tower Laptop Netbook Custom

Brand: * Acer Asus Compaq Dell Emachines Gateway HP Lenovo Sony Toshiba Custom

Model Number:

Operating System: * Windows XP Windows Vista Windows 7

Errors and Issues

Tell us what errors or issues you are experiencing, please try to include any error messages as best as possible *



[/code]

Your formcontent variable has no closing quotes…

Thank you for noticing that little mistake that could be troublesome. I fixed that, however, it is still not submitting to email… I have added some validations to the php code for it do require certain fields.
I feel like I may be doing too much to the code or not enough at all…

[php]<?php
if($_POST[‘submit’] == “Submit”);

$Client_Name = $_POST[‘Client_Name’];
$Client_Phone = $_POST[‘Client_Phone’];
$Client_Email = $_POST[‘Client_Email’];
$Type = $_POST[‘Type’];
$Brand = $_POST[‘Brand’];
$Model = $_POST[‘Model’];
$OS = $_POST[‘OS’];
$Errors = $_POST[‘Errors’];

$email_from = ‘[email protected]’;
$email_subject = “Client Form”;
$email_body ="$Client_Name, $Client_Phone, $Client_Email, $Type, $Brand, $Model, $OS, $Errors";

$to ="[email protected]";
$headers = “from: $email_from r\n”;

mail($to, $email_subject, $email_body);

$error = array ()
if(empty($_POST[‘Client_Name’])) {
$error [] = “required field”;
} else {
$Client_Name = htmlspecialchars($_POST[‘Client_Name’]);
}

$error = array ()
if(empty($_POST[‘Client_Phone’])) {
$error [] = “required field”;
} else {
$Client_Phone = htmlspecialchars($_POST[‘Client_Phone’]);
}

$error = array ()
if(empty($_POST[‘Client_Email’])) {
$error [] = “required field”;
} else {
$Client_Email = htmlspecialchars($_POST[‘Client_Email’]);
}

$error = array ()
if(empty($_POST[‘Type’])) {
$error [] = “required field”;
} else {
$Type = htmlspecialchars($_POST[‘Type’]);
}

$error = array ()
if(empty($_POST[‘Brand’])) {
$error [] = “required field”;
} else {
$Brand = htmlspecialchars($_POST[‘Brand’]);
}

$error = array ()
if(empty($_POST[‘OS’])) {
$error [] = “required field”;
} else {
$OS = htmlspecialchars($_POST[‘OS’]);
}

$error = array ()
if(empty($_POST[‘Errors’])) {
$error [] = “required field”;
} else {
$Errors = htmlspecialchars($_POST[‘Errors’]);
}

?>
[/php]

<html>
<body>
<form action="http://lfpctech.net/thanks/" method="post" enctype="multipart/form-data" name="Client Form" id="Client Form">
<p>Fields with * are required.</p>
<fieldset><legend>Client Information</legend>
<div class="field-item"><label>Name: *</label> <input maxlength="150" size="30" id="Client Name" name="Client_Name" type="text" title="" /><br /></div>
<div class="field-item">
<div><label>Phone: *</label> <input maxlength="20" size="20" id="Client phone" name="Client_Phone" type="text" title="" />
<p class="small">(555) 555-0000</p>
</div>
</div>
<div class="field-item">
<div><label>E-mail Address: *</label> <input class="" maxlength="30" size="20" id="Client Email" name="Client_Email" type="text" /></div>
</div>
</fieldset>
<fieldset><legend>Computer Information</legend>
<div class="field-item">
<div>
<p>Type of Computer: *<select name="Type" size="1">
<option>Desktop/Tower</option>
<option>Laptop</option>
<option>Netbook</option>
<option>Custom</option>
</select></p>
</div>
<div class="field-item">
<div>
<p>Brand: *<select name="Brand" size="1">
<option>Acer</option>
<option>Asus</option>
<option>Compaq</option>
<option>Dell</option>
<option>Emachines</option>
<option>Gateway</option>
<option>HP</option>
<option>Lenovo</option>
<option>Sony</option>
<option>Toshiba</option>
<option>Custom</option>
</select><br /></p>
<div class="field-item">
<div><label>Model Number:</label> <input type="text" name="Model" /></div>
</div>
<div class="field-item">
<div>
<p>Operating System: *<select name="OS" size="1">
<option>Windows XP</option>
<option>Windows Vista</option>
<option>Windows 7</option>
</select></p>
</div>
</div>
</div>
</div>
</div>
</fieldset>
<fieldset><legend>Errors and Issues</legend>
<div class="field-item">
<div>
<p>Tell us what errors or issues you are experiencing, please try to include any error messages as best as possible *</p>
<textarea name="Errors" rows="10" cols="100">
</textarea>
<br />
<br />
<input type="submit" name="submit" id="submit" value="Send" /> <input type="reset" value="Reset" /></div>
</div>
</fieldset>
</form>
	

</body>
</html>

Well, first, you shouldn’t use spaces inside of ID="" or name=""… they do not always work.
A form name shouldn’t be “client form”, maybe “client_form” or “ClientForm”. Makes sure it will work.

Also, in your code, this line: if($_POST[‘submit’] == “Submit”); Is a bit odd…

It is saying the field called “submit” must be equal to “Submit”… So, field “submit” is the form, but, why would you test it to a submit with a cap? Caps are inportant. All field names are cap-sensitive!

In your code you do have a submit button that you call “submit”, so I would change this line to:
if(isset($_POST[‘submit’])

Also, you do not handle the submit button. You end it with a ; !!! so it does nothing…
In general terms this should be handled like this…

if(isset($_POST[‘submit’]) { //Note the opening bracket meaning this group of code…
//… Here do whatever you want if the submit button has been pressed…
}
//… Here do other PHP code that is run even if the submit button was not pressed…

Hope that helps… Good luck!

Sponsor our Newsletter | Privacy Policy | Terms of Service