Jump to content

Help with PHP form on GoDaddy.com


aevri

Recommended Posts

I been trying to figure out how to set up a form to collect information for a health insurance application and email the information to my inbox. I don't know much about PHP, but I'd like to learn soon. I keep getting errors when I try to use the form.

 

The form is located here: http://tri-stateinsurance.com/health.htm.

HTML:

<form action="info.php" method="post"><br /> First name:
<input name="firstname" size="10" type="text" />    Last name:

<input name="lastname" size="15" type="text" /><br /><br />
Birthdate: <select name="month"> <option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option> 
<option value="April">April</option> 
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select> <select name="day"> <option value="1">1</option> 
<option value="2">2</option> <option value="3">3</option> <option value="4">4</option>
<option value="5">5</option> <option value="6">6</option> <option value="7">6</option>
<option value="8">8</option> <option value="9">9</option> <option value="10">10</option>
<option value="11">11</option> <option value="12">12</option> <option value="13">13</option>
<option value="14">14</option> <option value="15">15</option> <option value="16">16</option>
<option value="17">17</option> <option value="18">18</option> <option value="19">19</option>
<option value="20">20</option> <option value="21">21</option> <option value="22">22</option>
<option value="23">23</option> <option value="24">24</option> <option value="25">25</option>
<option value="26">26</option> <option value="27">27</option> <option value="28">28</option>
<option value="29">29</option> <option value="30">30</option> <option value="31">31</option>
</select> 
<input name="year" size="5" type="text" /> <br /><br />
Sex: <input name="sex" value="male" type="radio" /> Male  
<input name="sex" value="female" type="radio" /> Female
<br /><br /> Nicotine Use:
<input name="nicotine" value="Cigarettes" type="checkbox" /> Cigarettes
<input name="nicotine" value="Chewing Tobacco" type="checkbox" /> Chewing Tobacco
<input name="nicotine" value="Other" type="checkbox" /> Other
<br /><br /> Comments:<br /> <textarea name="comments" rows="3" cols="50"></textarea> <br /><br />Email:
<input name="email" size="10" type="text" /><br /><br /><input value="Submit" type="submit" /></form>

 

And here is the .php file: http://tri-stateinsurance.com/info.php

PHP:

<?php 
$to = "[email protected]";  
$from = $_REQUEST['email'] ; 
$name = $_REQUEST['firstname'] ;
$headers = "From: $email"; 
$subject = "Health Insurance Information";

$fields = array(); 
$fields{"firstname"} = "First Name"; 
$fields{"lastname"} = "Last Name" ;
$fields{"month"} = "Month"; 
$fields{"day"} = "Day"; 
$fields{"year"} = "Year";
$fields{"sex"} = "Sex"; 
$fields{"nicotine"} = "Nicotine Usage"; 
$fields{"comments"} = "Comments"; 


$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){    $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } 

$headers2 = "From: noreply@[email protected]"; 
$subject2 = "Thank you for contacting us"; 
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usually within 48 hours. 
If you have any more questions, please consult our website at [url=http://www.tri-stateinsurance.com]www.tri-stateinsurance.com[/url]";

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 {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send) {
header("Location: [url]http://www.hfhbeauco.org/thankyou.html[/url]");
exit();
} else {
print "We encountered an error sending your mail, please notify [email protected]";
}
}
}

 

I hope you all will be able to help me. My dad has asked me to set up a website for him by this weekend O_O.

Link to comment
https://forums.phpfreaks.com/topic/201520-help-with-php-form-on-godaddycom/
Share on other sites

I have a website hosted on godaddy and my mail works just fine...

 

What I do though...is different.  I don't use the headers variable in the mail function.  Try taking that out, leaving just the mail(email_address,subject,message);

 

I don't know if it will make a difference...but it's worth a shot.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.