Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
cant get form mail to work
Old 03-07-2010, 08:25 AM cant get form mail to work
Webmaster Talker

Posts: 611
Trades: 0
hi. i want the user to choose one of the radio button selections, and mail me the results, its not working, i get back "blarg".

here is the html

Code:
<div align="center">
  <form id="form1" name="form1" method="post" action="userform1.php">
    <p>
  
        <input type="radio" name="RadioGroup1" value="five" id="five" />
        5 
   
   
      <input type="radio" name="RadioGroup1" value="ten" id="ten" />
      10 
 
   
        <input type="radio" name="RadioGroup1" value="fifteen" id="fifteen" />
        15 
 
    
        <input type="radio" name="RadioGroup1" value="twenty" id="twenty" />
        20 
   
     
        <input type="radio" name="RadioGroup1" value="twenty_five" id="twenty_five" />
        25 
  
   
        <input type="radio" name="RadioGroup1" value="thirty" id="thirty" />
        30 
    
    </p> 
    <input type="submit" name="submit " id="submit " value="submit" /> 
   
  </form>
</div>
here is the php

Code:
<?php 
if(isset($_POST['submit'])) { 
$to = "derekpainter1@hotmail.com"; 
$subject = "How many attributes to use on bossgrade.com";
foreach($_POST as $key => $value) {  /*loops through the POST array and uses the form values*/
  $$key = $value;
}
  
$body = "Feedback from user:  \n Number of attributes should be : $five \n  Number of attributes should be : $ten  \n   Number of attributes should be : $fifteen \n   Number of attributes should be : $twenty \n   Number of attributes should be : $twenty_five \n   Number of attributes should be : $thirty   \n "; 
  
echo "Thank you for filling out my feedback form!"; 
mail($to, $subject, $body); 
} else { 
echo "blarg!"; 
} 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Feedback form</title>
</head>

<body>
</body>
</html>
silverglade is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-07-2010, 12:48 PM Re: cant get form mail to work
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Two things:
Code:
<input type="submit" name="submit " id="submit " value="submit" />
The trailing space in the name attribute is what is causing the problem. Remove it.

Also, read the mail() documentation carefully: http://us2.php.net/manual/en/function.mail.php

Even though the headers are an optional parameter, the from header is required. The only way it will work without including headers is if you specify a default from address in your php.ini
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 03-07-2010, 03:43 PM Re: cant get form mail to work
Webmaster Talker

Posts: 611
Trades: 0
awesome! thank you so much for that. i was waiting all day to get that fixed. so thank you. also, in my email, i wanted to be able to tell which radio button they pressed. but as it is coded now, all i get in my email is this


Feedback from user:
Number of attributes should be :
Number of attributes should be :
Number of attributes should be :
Number of attributes should be :
Number of attributes should be :
Number of attributes should be :
silverglade is offline
Reply With Quote
View Public Profile
 
Old 03-07-2010, 03:59 PM Re: cant get form mail to work
MattGoucher's Avatar
Skilled Talker

Posts: 64
Name: Matt
Location: California
Trades: 0
You seem to be missing your mail headers. Most mail providers will not except mail that is not from anyone. Also you might need to specify a SMTP server. Heres how:

PHP Code:
mail($To$Subject$Body$Headers); 
Notice the headers. If you don't have them, your mail might not get sent. The simplest way to add headers for this issue would be like this:

PHP Code:
$Headers "From: You@YourDomain.com"
Also, If you want more information on how to do this, check This out.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Invalid Code On A New Website Is Like Having A New Car With A Broken Windshield
MattGoucher is offline
Reply With Quote
View Public Profile Visit MattGoucher's homepage!
 
Old 03-07-2010, 04:05 PM Re: cant get form mail to work
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Your problem is here:
PHP Code:
foreach($_POST as $key => $value) {  /*loops through the POST array and uses the form values*/
  
$$key $value;
}
  
$body "Feedback from user:  \n Number of attributes should be : $five \n  Number of attributes should be : $ten  \n   Number of attributes should be : $fifteen \n   Number of attributes should be : $twenty \n   Number of attributes should be : $twenty_five \n   Number of attributes should be : $thirty   \n "
I'm not exactly sure what you are going for, but it looks like you are assuming PHP uses the id attribute of an input field as the key in POST data. It doesn't; it uses the name attribute. The value you are looking for is stored in the $RadioGroup1 variable.

Try:
PHP Code:
$body "Feedback from user:  \n Number of attributes should be : " $_POST['RadioGroup1']; 
You should get rid of that for loop altogether. In general you shouldn't use the entire $_POST array to set variables without doing any checking.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 03-07-2010 at 04:09 PM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 03-07-2010, 04:20 PM Re: cant get form mail to work
Webmaster Talker

Posts: 611
Trades: 0
great thanks very much. that is much better. but i still get the following in my email. i cant tell which radio button they pressed. any more help greatly appreciated. thanks. derek

Feedback from user:
Number of attributes should be :
Number of attributes should be :
Number of attributes should be :
Number of attributes should be :
Number of attributes should be :
Number of attributes should be :
silverglade is offline
Reply With Quote
View Public Profile
 
Old 03-07-2010, 04:22 PM Re: cant get form mail to work
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Are you sure you updated the code correctly?

PHP Code:
$body "Feedback from user:  \n Number of attributes should be : " $_POST['RadioGroup1']; 
It looks like you are still using the old code.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 03-07-2010, 04:27 PM Re: cant get form mail to work
Webmaster Talker

Posts: 611
Trades: 0
thank you so much nullpointer and mattgoucher!!! IT WORKS!! hahaha. it took me all day to get help for that. thank you so much for looking at my code and helping. it works! YAY! hehe. thanks. derek
silverglade is offline
Reply With Quote
View Public Profile
 
Old 03-07-2010, 04:49 PM Re: cant get form mail to work
MattGoucher's Avatar
Skilled Talker

Posts: 64
Name: Matt
Location: California
Trades: 0
Haha, I hope I helped a bit. Congrats on your mail script. If you hadn't figured it out by now, I would have sent you mine
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Invalid Code On A New Website Is Like Having A New Car With A Broken Windshield
MattGoucher is offline
Reply With Quote
View Public Profile Visit MattGoucher's homepage!
 
Reply     « Reply to cant get form mail to work
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.05950 seconds with 12 queries