Current location: Hot Scripts Forums » Programming Languages » PHP » help needed with php mail form !


help needed with php mail form !

Reply
  #1 (permalink)  
Old 09-09-10, 06:27 AM
photoworks photoworks is offline
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 &quot;Other&quot; 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 09-09-10, 08:37 AM
photoworks photoworks is offline
Newbie Coder
 
Join Date: Sep 2010
Location: Greenock
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
anyone, please ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 09-09-10, 12:45 PM
Golith Golith is offline
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
__________________
Its My script and I'll if I want to
www.cictradinggroup.com.au
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 09-09-10, 01:06 PM
photoworks photoworks is offline
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 09-10-10, 11:21 AM
Golith Golith is offline
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
HTML Code:
<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>
PHP Code:

<?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
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
__________________
Its My script and I'll if I want to
www.cictradinggroup.com.au
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 09-10-10, 11:41 AM
photoworks photoworks is offline
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";
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 09-10-10, 12:27 PM
Golith Golith is offline
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>
PHP Code:





$to 
$_REQUEST['sendto'] ;
$from $_REQUEST['Email'] ;
$name $_REQUEST['Name'] ;
$list $_REQUEST['list'];
$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 
__________________
Its My script and I'll if I want to
www.cictradinggroup.com.au

Last edited by Golith; 09-10-10 at 12:49 PM. Reason: update code
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 09-10-10, 12:29 PM
photoworks photoworks is offline
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 09-10-10, 01:28 PM
photoworks photoworks is offline
Newbie Coder
 
Join Date: Sep 2010
Location: Greenock
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Golith View Post
i would be doing this inside the html first


PHP Code:





$to 
$_REQUEST['sendto'] ;
$from $_REQUEST['Email'] ;
$name $_REQUEST['Name'] ;
$list $_REQUEST['list'];
$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 
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>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 09-10-10, 02:01 PM
Golith Golith is offline
Newbie Coder
 
Join Date: Jun 2010
Posts: 87
Thanks: 6
Thanked 1 Time in 1 Post
the complete html file will be;

HTML Code:
<?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') {
$referral= 'checked';
}else if ($selected_radio == 'Facebook') {
$facebook= 'checked';
}else if ($selected_radio == 'Other') {
$other= 'checked';
}
}
?>

<form [B]name="submit1"[/B] 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 &quot;Other&quot; 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> 
the contact.php page will be
PHP Code:



$to 
$_REQUEST['sendto'] ; 
$from $_REQUEST['Email'] ; 
$name $_REQUEST['Name'] ; 
[
B]$list $_REQUEST['list']; [/B]
$headers "From: $from"
$subject "inquiry Email"

$fields = array(); 
$fields{"Name"} = "Name"
$fields{"Company"} = "Company"
$fields{"Email"} = "Email"
$fields{"Phone"} = "Phone"
[
B]$fields{"list"} = "Where did you hear about me "; [/B]
$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  
// ..... what ever ur condition are 
__________________
Its My script and I'll if I want to
www.cictradinggroup.com.au

Last edited by Golith; 09-10-10 at 02:06 PM. Reason: code change
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP or PHP which is better? nepala The Lounge 9 07-14-10 06:48 AM
BRAIN BUSTER... Why won't my PHP contact form work on a Yahoo server? thinktec PHP 11 11-19-09 03:11 PM
Space Above Form xavier039 CSS 1 07-13-09 11:52 PM
PHP Security alert: PHP mail() Function Lets Remote Users Inject E-mail Headers darkerstar PHP 4 04-29-07 08:14 PM


All times are GMT -5. The time now is 08:43 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.