Can you tell if I did something wrong with this send form?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
KT83
Forum Newbie
Posts: 5
Joined: Thu Jun 11, 2009 12:31 am

Can you tell if I did something wrong with this send form?

Post by KT83 »

Hi, I've created a survey but cannot get it to send the results to an email address. I know for sure it did work on the first try but for some reason when I tried to send it again without making any changes to it it wouldn't send. Could anyone tell me if this looks right?

FYI: The "id=contactform" that I use is a contact for I created for the feedback page. I wonder if I'd have to create a different one for the survey...

Code: Select all

 
//PHP FOR SENDING SURVEY RESULTS TO EMAIL//////////////////////////
 
if( isset($_POST["btnSubmit"]) ){
 
{
    ${$var} = $val;
}
 
$body_body .= "     Gender: | " . $gender . "\n";
$body_body .= "     Age Group: | " . $age . "\n";
 
 
$to = 'Admin <admin@pho411.ca>';
$subject = 'Pho411 Survey Results';
$body = $body_body;
mail($to, $subject, $body);
 
}
/////END OF PHP/////
 
 

Code: Select all

 
/////TPL FILE/////
 
<form method="post" id="contactForm">
 
  <b>What is your gender?</b>
<br /><br />
<table border="0">
    <tr>
      <td><input type="radio" name="gender" value="male"> &nbsp;&nbsp;Male </td>
    </tr>
    <tr>
      <td><input type="radio" name="gender" value="female"> &nbsp;&nbsp;Female</td>
    </tr>
   </table>
<br /><br />
 
   <b>What is your age group?</b>
   <br /><br />
   <table border="0">
    <tr>
      <td><input type="radio" name="age" value="under20" /> &nbsp;&nbsp;Under 20 </td>
    </tr>
  </table>
<br /><br />
<input type="submit" value="submit" name="submit" />
</form>
 
////END OF TPL////
 
Thanks in advance!
Last edited by Benjamin on Fri Jun 12, 2009 1:42 am, edited 2 times in total.
Reason: Added [code=php] tags.
globezone
Forum Newbie
Posts: 7
Joined: Wed Jun 10, 2009 4:57 am

Re: Can you tell if I did something wrong with this send form?

Post by globezone »

Code: Select all

 
if( isset($_POST["btnSubmit"]) ){
 
{
${$var} = $val;
}
 ....
 
 
}
 
"btnSubmit" - i cant see this name in form must be "submit"

and this i am not shure ....

Code: Select all

 
{
${$var} = $val;
}
 
try this ...

Code: Select all

 
if(filter_has_var(INPUT_POST, 'submit')){
 
$body_body  = "";
$body_body .= " Gender: | " . $_POST['gender'] . "\n";
$body_body .= " Age Group: | " . $_POST['age'] . "\n";
 
 
$to = 'Admin <admin@pho411.ca>';
$subject = 'Pho411 Survey Results';
mail($to, $subject, $body_body);
 
}
 
Last edited by Benjamin on Fri Jun 12, 2009 1:43 am, edited 1 time in total.
Reason: Changed code type from text to php.
KT83
Forum Newbie
Posts: 5
Joined: Thu Jun 11, 2009 12:31 am

Re: Can you tell if I did something wrong with this send form?

Post by KT83 »

I tried that but the email wasn't sent. Not sure what else is involved that I might have overlooked.

Does anyone else have any ideas? Thanks.
mischievous
Forum Commoner
Posts: 71
Joined: Sun Apr 19, 2009 8:59 pm

Re: Can you tell if I did something wrong with this send form?

Post by mischievous »

This should work... however, not tested. Make sure when you use $variable .= "value"; that it initially has $variable = "value";

Code: Select all

 
if(isset($_POST["submit"]))
{
 
//Setup Email Format
$to = 'Admin <admin@pho411.ca>';
$subject = 'Pho411 Survey Results';
 
//Setup Email Content
$body = " Gender: | ".$_POST["gender"]."\n";
$body .= " Age Group: | ".$_POST["age"]."\n";
 
//Send Email
mail($to, $subject, $body);
 
}
//<---------END of PHP File
 
 
//TPL FILE---------->
 
<form method="post" id="contactForm">
 
<b>What is your gender?</b>
<br /><br />
<table border="0">
<tr>
<td><input type="radio" name="gender" value="male"> &nbsp;&nbsp;Male </td>
</tr>
<tr>
<td><input type="radio" name="gender" value="female"> &nbsp;&nbsp;Female</td>
</tr>
</table>
<br /><br />
 
<b>What is your age group?</b>
<br /><br />
<table border="0">
<tr>
<td><input type="radio" name="age" value="under20" /> &nbsp;&nbsp;Under 20 </td>
</tr>
</table>
<br /><br />
<input type="submit" value="submit" name="submit" />
</form>
 
//<-------END OF TPL
 
Last edited by Benjamin on Fri Jun 12, 2009 4:18 am, edited 1 time in total.
Reason: Changed code type from text to php.
Post Reply