help needed with php mail form !

09-09-10, 06:27 AM
|
|
Newbie Coder
|
|
Join Date: Sep 2010
Location: Greenock
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
help needed with php mail form !
I have an issue with my contact page on my website.
i recently migrated my website to a new server (with php 5) and since, i am having the following issue :
on my contact page (contact.html), i have the following form :
Quote:
<form method="post" action="contact.php">
<table width="471" align="center" cellspacing="4">
<tr class="subhead">
<td width="146" bgcolor="#FFFFFF"><span class="style5">Subject</span></td>
<td width="307" bgcolor="#FFFFFF"><span class="style5">
<select name="sendto">
<option value="inquiry@pwks.net" selected="selected">General inquiry</option>
<option value="booking@pwks.net">booking inquiry</option>
<option value="feedback@pwks.net">Feedback</option>
</select>
</span></td>
</tr>
<tr class="subhead">
<td bgcolor="#FFFFFF"><span class="style5"><font color="red">*</font> Name:</span></td>
<td bgcolor="#FFFFFF"><input name="Name" size="25" /></td>
</tr>
<tr class="subhead">
<td bgcolor="#FFFFFF"><span class="style5"><font color="red">*</font> Email:</span></td>
<td bgcolor="#FFFFFF"><input name="Email" size="25" /></td>
</tr>
<tr class="subhead">
<td bgcolor="#FFFFFF"><span class="style5">Company:</span></td>
<td bgcolor="#FFFFFF"><input name="Company" size="25" /></td>
</tr>
<tr class="subhead">
<td bgcolor="#FFFFFF"><span class="style5">Phone:</span></td>
<td bgcolor="#FFFFFF"><input name="Phone" size="25" /></td>
</tr>
<tr class="subhead">
<td bgcolor="#FFFFFF"><span class="style5"></span></td>
<td bgcolor="#FFFFFF"><span class="style5"></span></td>
</tr>
<tr class="subhead">
<td valign="top" bgcolor="#FFFFFF"><span class="style5">Where did you hear about me:</span></td>
<td bgcolor="#FFFFFF"><span class="style5">
<input type="radio" name="list" value="Search engine" />
Search engine<br />
<input type="radio" name="list" value="Referral" />
Referral<br />
<input type="radio" name="list" value="Advertising" />
Advertising<br />
<input type="radio" name="list" value="Facebook" />
Facebook <br />
<input type="radio" name="list" value="Other" />
Other <br />
</span></td>
</tr>
<tr class="subhead">
<td valign="top" bgcolor="#FFFFFF"><span class="style5">if "Other" please specify</span></td>
<td bgcolor="#FFFFFF"><input name="Specify" size="25" /></td>
</tr>
<tr class="subhead">
<td valign="top" bgcolor="#FFFFFF"><span class="style5">Message:</span></td>
<td bgcolor="#FFFFFF"><span class="style5">
<textarea name="Message" cols="35" rows="6" wrap="physical"></textarea>
</span></td>
</tr>
<tr class="subhead">
<td colspan="2" align="center" bgcolor="#FFFFFF"><input name="send" type="submit" value="Submit" /></td>
</tr>
<tr class="subhead">
<td colspan="2" align="center" bgcolor="#FFFFFF"><span class="style5"><small>A <font color="red">*</font> indicates a field is required</small></span></td>
</tr>
</table>
</form>
|
on the contact.php page, here is the php code :
Quote:
<?php
$to = $_REQUEST['sendto'] ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "inquiry Email";
$fields = array();
$fields{"Name"} = "Name";
$fields{"Company"} = "Company";
$fields{"Email"} = "Email";
$fields{"Phone"} = "Phone";
$fields{"list"} = "Where did you hear about me ";
$fields{"Specify"} = "Specify";
$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: info@pwks.net";
$subject2 = "Thank you for contacting me";
$autoreply = "Thank you for contacting me. I will get back to you as soon as possible. Please do not reply to this message";
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";}
if($list == '') {print "You have not selected an option for 'where did you hear about me', please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: http://www.pwks.net/thankyou.html" );}
else
{print "We encountered an error sending your mail, please notify info@pwks.net"; }
}
}
?>
|
when i fill in the form in contact.html page and submit , i get the error message :
Quote:
|
You have not selected an option for 'where did you hear about me', please go back and try again
|
I do not understand since on my old server, the form was working fine and i did not change the code. It looks like, somehow, the html form is not passing any data for the radio buttons
Is there is there anyone who can help ?
Last edited by photoworks; 09-09-10 at 06:29 AM.
Reason: corrections
|

09-09-10, 08:37 AM
|
|
Newbie Coder
|
|
Join Date: Sep 2010
Location: Greenock
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
|

09-09-10, 12:45 PM
|
|
Newbie Coder
|
|
Join Date: Jun 2010
Posts: 87
Thanks: 6
Thanked 1 Time in 1 Post
|
|
|
$list is missing??
hi there
So far I can not see a reference to $list in the contact.php page so it will always test $list as empty.
make sure you declare $list first like the other elements in the form
|

09-09-10, 01:06 PM
|
|
Newbie Coder
|
|
Join Date: Sep 2010
Location: Greenock
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i don't understand, it looks like $list is declared in the contact.php code :
Quote:
$fields = array();
$fields{"Name"} = "Name";
$fields{"Company"} = "Company";
$fields{"Email"} = "Email";
$fields{"Phone"} = "Phone";
$fields{"list"} = "Where did you hear about me ";
$fields{"Specify"} = "Specify";
$fields{"Message"} = "Message";
|
If i am mistaken, could you let me know how to declare $list in the contact.php.
|

09-10-10, 11:21 AM
|
|
Newbie Coder
|
|
Join Date: Jun 2010
Posts: 87
Thanks: 6
Thanked 1 Time in 1 Post
|
|
Here is the specifics of list from html form
As i follow the data from html to php there is declaration for $_REQUEST --> to, for, name but there is none for list ... $from is associated with email ... $to is associated with sendto ... $name is associated with name .. but there is no $list = $_REQUEST['list'] or however you want to pass list onto the php page.
hope this helps in pointing you in the right direction. good effort thou thus far 
|

09-10-10, 11:41 AM
|
|
Newbie Coder
|
|
Join Date: Sep 2010
Location: Greenock
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
so should i write as follows :
Quote:
$to = $_REQUEST['sendto'] ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "inquiry Email";
$fields = array();
$fields{"Name"} = "Name";
$fields{"Company"} = "Company";
$fields{"Email"} = "Email";
$fields{"Phone"} = "Phone";
$fields= list();
$fields{"Specify"} = "Specify";
$fields{"Message"} = "Message";
|
|

09-10-10, 12:27 PM
|
|
Newbie Coder
|
|
Join Date: Jun 2010
Posts: 87
Thanks: 6
Thanked 1 Time in 1 Post
|
|
i would be doing this inside the html first
Quote:
<?PHP
// make sure that all values are set to unchecked in case the page has been refreshed
$Search engine_status = 'unchecked';
$Advertising = 'unchecked';
$referral_status = 'unchecked';
$Facebook = 'unchecked';
$Other = 'unchecked';
if (isset($_POST['Submit1'])) {
$selected_radio = $_POST['list'];
if ($selected_radio == 'Search engine') {
$searchengine= 'checked';
}else if ($selected_radio == 'Advertising') {
$adveretising= 'checked';
}else if ($selected_radio == 'referral') {
$adveretising= 'checked';
}else if ($selected_radio == 'Facebook') {
$adveretising= 'checked';
}else if ($selected_radio == 'Other') {
$adveretising= 'checked';
}
}
?>
// To get the value of a radio button with PHP code, again you access the NAME attribute of the HTML form elements
so add name='submit1' to the <form>
|
Last edited by Golith; 09-10-10 at 12:49 PM.
Reason: update code
|

09-10-10, 12:29 PM
|
|
Newbie Coder
|
|
Join Date: Sep 2010
Location: Greenock
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
could anyone provide the information about the missing php code for the radio button onthe contact.php page.
|

09-10-10, 01:28 PM
|
|
Newbie Coder
|
|
Join Date: Sep 2010
Location: Greenock
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Golith
i would be doing this inside the html first
|
Where exactly do i put that piece of code in the html page :
Quote:
<?PHP
// make sure that all values are set to unchecked in case the page has been refreshed
$Search engine_status = 'unchecked';
$Advertising = 'unchecked';
$referral_status = 'unchecked';
$Facebook = 'unchecked';
$Other = 'unchecked';
if (isset($_POST['Submit1'])) {
$selected_radio = $_POST['list'];
if ($selected_radio == 'Search engine') {
$searchengine= 'checked';
}else if ($selected_radio == 'Advertising') {
$adveretising= 'checked';
}else if ($selected_radio == 'referral') {
$adveretising= 'checked';
}else if ($selected_radio == 'Facebook') {
$adveretising= 'checked';
}else if ($selected_radio == 'Other') {
$adveretising= 'checked';
}
}
?>
// To get the value of a radio button with PHP code, again you access the NAME attribute of the HTML form elements
so add name='submit1' to the <form>
|
|

09-10-10, 02:01 PM
|
|
Newbie Coder
|
|
Join Date: Jun 2010
Posts: 87
Thanks: 6
Thanked 1 Time in 1 Post
|
|
the complete html file will be;
the contact.php page will be
Last edited by Golith; 09-10-10 at 02:06 PM.
Reason: code change
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|