help needed for php form that sends email

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
deblundgren
Forum Newbie
Posts: 1
Joined: Thu Sep 21, 2006 2:41 pm

help needed for php form that sends email

Post by deblundgren »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I am new to php and just learning. I am having trouble with this form not collecting all information from checkboxes.
This is all working fine with the exception of the checkboxes. When more than one checkbox is selected it still only emails one choice.
Any help would be appreciated.

Form
[syntax="html"]<form action="submitted2.php" method="POST">
                    <input type="hidden" name="recipient" value="deblundgren@comcast.net">
                    <input type="hidden" name="redirect" value="thankyou.html">
                    <input type="hidden" name="subject" value="WebMail">
                    <input type="hidden" name="missing_fields_redirect" value="oops.html">
                    <input type="hidden" name="required" value="ContactName,email">
                    <input type="hidden" name="sort"
          value="order:ContactName,email">
                    <input
          type="hidden" name="env_report" value="REMOTE_HOST,HTTP_USER_AGENT">
                    <table width="507" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border:1px solid #cccccc">
                      <tr bgcolor="#f5f5f5">
                        <td height="17" colspan="3" valign="middle" nowrap style="padding:7px 5px 7px 5px; border-bottom:1px solid #cccccc"><strong>Contact Information </strong></td>
                      </tr>
                      <tr>
                        <td colspan="2" valign="middle" nowrap><div align="right" class="small" style="padding:4px 1px 4px 1px">*First Name:&nbsp; </div></td>
                        <td width="372" valign="middle" nowrap style="padding:4px 1px 4px 1px"><input name="ContactName" class="inbox" size="25"></td>
                      </tr>
                      <tr>
                        <td colspan="2"><div align="right" class="small" style="padding:1px 1px 4px 1px">*Email&nbsp;Address: </div></td>
                        <td style="padding:1px 1px 4px 1px"><input name="email" class="inbox" size="25"></td>
                      </tr>
                      <tr bgcolor="#f5f5f5">
                        <td height="14" colspan="3" valign="middle" nowrap style="padding:4px 5px 4px 5px; border-bottom:1px solid #cccccc; border-top:1px solid #cccccc"><strong>1. My interest in Web conferencing is for:</strong></td>
                      </tr>
                      <tr>
                        <td colspan="3"><table width="56%"  border="0" cellspacing="0" cellpadding="0" style="background-color:#FFFFFF">
                            <tr height="1">
                              <th height="1" style="background-color:#FFFFFF"><img src="images/spacer.gif" height="3"></th>
                              <th height="1" style="background-color:#FFFFFF"><img src="images/spacer.gif" height="3"></th>
                              <th height="1" style="background-color:#FFFFFF"><img src="images/spacer.gif" height="3"></th>
                            </tr>
                            <tr>
                              <th width="18%" style="background-color:#FFFFFF">&nbsp;</th>
                              <th width="8%" style="background-color:#FFFFFF"><input name="what" type="radio" value="Business use"></th>
                              <th width="74%" style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">Business use</div></th>
                            </tr>
                            <tr>
                              <th style="background-color:#FFFFFF">&nbsp;</th>
                              <th style="background-color:#FFFFFF"><input name="what" type="radio" value="Personal use"></th>
                              <th style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">Personal use</div></th>
                            </tr>
                            <tr>
                              <th style="background-color:#FFFFFF">&nbsp;</th>
                              <th style="background-color:#FFFFFF"><input name="what" type="radio" value="Both"></th>
                              <th style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">Both </div></th>
                            </tr>
                            <tr height="1">
                              <th height="1" style="background-color:#FFFFFF"><img src="images/spacer.gif" height="3"></th>
                              <th height="1" style="background-color:#FFFFFF"><img src="images/spacer.gif" height="3"></th>
                              <th height="1" style="background-color:#FFFFFF"><img src="images/spacer.gif" height="3"></th>
                            </tr>
                            <tr>
                          </table></td>
                      </tr>
                      <tr bgcolor="#f5f5f5">
                        <td height="14" colspan="3" valign="middle" nowrap style="padding:4px 5px 4px 5px; border-bottom:1px solid #cccccc; border-top:1px solid #cccccc"><strong>2. The Be-Intouch features that are MOST IMPORTANT to me are (click all that apply):</strong></td>
                      </tr>
                      <tr>
                        <td colspan="3"><table width="56%"  border="0" cellspacing="0" cellpadding="0" style="background-color:#FFFFFF">
                            <tr height="1">
                              <th height="1" style="background-color:#FFFFFF"><img src="images/spacer.gif" height="3"></th>
                              <th height="1" style="background-color:#FFFFFF"><img src="images/spacer.gif" height="3"></th>
                              <th height="1" style="background-color:#FFFFFF"><img src="images/spacer.gif" height="3"></th>
                            </tr>
                            <tr>
                              <th width="18%" style="background-color:#FFFFFF">&nbsp;</th>
                              <th width="8%" style="background-color:#FFFFFF"> <input type="checkbox" name="most_important" value="Video"></th>
                              <th width="74%" style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">Video</div></th>
                            </tr>
                            <tr>
                              <th width="18%" style="background-color:#FFFFFF">&nbsp;</th>
                              <th width="8%" style="background-color:#FFFFFF"> <input type="checkbox" name="most_important" value="Voice"></th>
                              <th width="74%" style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">Voice</div></th>
                            </tr>
                            <tr>
                              <th width="18%" style="background-color:#FFFFFF">&nbsp;</th>
                              <th width="8%" style="background-color:#FFFFFF"> <input type="checkbox" name="most_important" value="Text Messaging"></th>
                              <th width="74%" style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">Text Messaging</div></th>
                            </tr>
                            <tr>
                              <th width="18%" style="background-color:#FFFFFF">&nbsp;</th>
                              <th width="8%" style="background-color:#FFFFFF"> <input type="checkbox" name='most_important' value="White Board"></th>
                              <th width="74%" style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">White Board</div></th>
                            </tr>
                            <tr>
                              <th width="18%" style="background-color:#FFFFFF">&nbsp;</th>
                              <th width="8%" style="background-color:#FFFFFF"> <input type="checkbox" name='most_important' value="Creation of Tutorials"></th>
                              <th width="74%" style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">Creation of Tutorials</div></th>
                            </tr>
                            <tr>
                              <th width="18%" style="background-color:#FFFFFF">&nbsp;</th>
                              <th width="8%" style="background-color:#FFFFFF"> <input type="checkbox" name="most_important" value="Creation of Presentations"></th>
                              <th width="74%" style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">Creation of Presentations</div></th>
                            </tr>
                            <tr>
                              <th width="18%" style="background-color:#FFFFFF">&nbsp;</th>
                              <th width="8%" style="background-color:#FFFFFF"> <input type="checkbox" name="most_important" value="PowerPoint Presenter"></th>
                              <th width="74%" style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">PowerPoint Presenter</div></th>
                            </tr>
                            <tr>
                              <th width="18%" style="background-color:#FFFFFF">&nbsp;</th>
                              <th width="8%" style="background-color:#FFFFFF"> <input type="checkbox" name="most_important" value="Co-Browser"></th>
                              <th width="74%" style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">Co-Browser</div></th>
                            </tr>
                            <tr>
                              <th width="18%" style="background-color:#FFFFFF">&nbsp;</th>
                              <th width="8%" style="background-color:#FFFFFF"> <input type="checkbox" name="most_important" value="Document Sharing"></th>
                              <th width="74%" style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">Document Sharing</div></th>
                            </tr>
                            <tr>
                              <th width="18%" style="background-color:#FFFFFF">&nbsp;</th>
                              <th width="8%" style="background-color:#FFFFFF"> <input type="checkbox" name="most_important" value="Live Meeting Recorder"></th>
                              <th width="74%" style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">Live Meeting Recorder</div></th>
                            </tr>
                            <tr>
                              <th width="18%" style="background-color:#FFFFFF">&nbsp;</th>
                              <th width="8%" style="background-color:#FFFFFF"> <input type="checkbox" name="most_important" value="Archiving Data"></th>
                              <th width="74%" style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">Archiving Data</div></th>
                            </tr>
                            <tr>
                              <th width="18%" style="background-color:#FFFFFF">&nbsp;</th>
                              <th width="8%" style="background-color:#FFFFFF"> <input type="checkbox" name="most_important" value="other"></th>
                              <th width="74%" style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">Other</div></th>
                            </tr>
                          </table></td>
                      </tr>
                      <tr bgcolor="#f5f5f5">
                        <td height="14" colspan="3" valign="middle" nowrap style="padding:4px 5px 4px 5px; border-bottom:1px solid #cccccc; border-top:1px solid #cccccc"><strong>3. The Be-Intouch features that I LIKED the MOST are (click all that apply):</strong></td>
                      </tr>
                      <tr>
                        <td colspan="3"><table width="56%"  border="0" cellspacing="0" cellpadding="0" style="background-color:#FFFFFF">
                            <tr height="1">
                              <th height="1" style="background-color:#FFFFFF"><img src="images/spacer.gif" height="3"></th>
                              <th height="1" style="background-color:#FFFFFF"><img src="images/spacer.gif" height="3"></th>
                              <th height="1" style="background-color:#FFFFFF"><img src="images/spacer.gif" height="3"></th>
                            </tr>
                            <tr>
                              <th width="18%" style="background-color:#FFFFFF">&nbsp;</th>
                              <th width="8%" style="background-color:#FFFFFF"> <input type="checkbox" name="liked" value="Video"></th>
                              <th width="74%" style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">Video</div></th>
                            </tr>
                            <tr>
                              <th width="18%" style="background-color:#FFFFFF">&nbsp;</th>
                              <th width="8%" style="background-color:#FFFFFF"> <input type="checkbox" name="liked" value="Voice"></th>
                              <th width="74%" style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">Voice</div></th>
                            </tr>
                            <tr>
                              <th width="18%" style="background-color:#FFFFFF">&nbsp;</th>
                              <th width="8%" style="background-color:#FFFFFF"> <input type="checkbox" name="liked" value="Text Messaging"></th>
                              <th width="74%" style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">Text Messaging</div></th>
                            </tr>
                            <tr>
                              <th width="18%" style="background-color:#FFFFFF">&nbsp;</th>
                              <th width="8%" style="background-color:#FFFFFF"> <input type="checkbox" name='liked' value="White Board"></th>
                              <th width="74%" style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">White Board</div></th>
                            </tr>
                            <tr>
                              <th width="18%" style="background-color:#FFFFFF">&nbsp;</th>
                              <th width="8%" style="background-color:#FFFFFF"> <input type="checkbox" name='liked' value="Creation of Tutorials"></th>
                              <th width="74%" style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">Creation of Tutorials</div></th>
                            </tr>
                            <tr>
                              <th width="18%" style="background-color:#FFFFFF">&nbsp;</th>
                              <th width="8%" style="background-color:#FFFFFF"> <input type="checkbox" name="liked" value="Creation of Presentations"></th>
                              <th width="74%" style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">Creation of Presentations</div></th>
                            </tr>
                            <tr>
                              <th width="18%" style="background-color:#FFFFFF">&nbsp;</th>
                              <th width="8%" style="background-color:#FFFFFF"> <input type="checkbox" name="liked" value="PowerPoint Presenter"></th>
                              <th width="74%" style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">PowerPoint Presenter</div></th>
                            </tr>
                            <tr>
                              <th width="18%" style="background-color:#FFFFFF">&nbsp;</th>
                              <th width="8%" style="background-color:#FFFFFF"> <input type="checkbox" name="liked" value="Co-Browser"></th>
                              <th width="74%" style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">Co-Browser</div></th>
                            </tr>
                            <tr>
                              <th width="18%" style="background-color:#FFFFFF">&nbsp;</th>
                              <th width="8%" style="background-color:#FFFFFF"> <input type="checkbox" name="liked" value="Document Sharing"></th>
                              <th width="74%" style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">Document Sharing</div></th>
                            </tr>
                            <tr>
                              <th width="18%" style="background-color:#FFFFFF">&nbsp;</th>
                              <th width="8%" style="background-color:#FFFFFF"> <input type="checkbox" name="liked" value="Live Meeting Recorder"></th>
                              <th width="74%" style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">Live Meeting Recorder</div></th>
                            </tr>
                            <tr>
                              <th width="18%" style="background-color:#FFFFFF">&nbsp;</th>
                              <th width="8%" style="background-color:#FFFFFF"> <input type="checkbox" name="liked" value="Archiving Data"></th>
                              <th width="74%" style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">Archiving Data</div></th>
                            </tr>
                            <tr>
                              <th width="18%" style="background-color:#FFFFFF">&nbsp;</th>
                              <th width="8%" style="background-color:#FFFFFF"> <input type="checkbox" name="liked" value="other"></th>
                              <th width="74%" style="background-color:#FFFFFF"><div align="left" class="small" style="font-weight:100">Other</div></th>
                            </tr>
                          </table></td>
                      </tr>
                      <tr>
                        <td colspan="3">&nbsp;</td>
                      </tr>
                      <tr>
                        <td width="107">&nbsp;</td>
                        <td colspan="2">&nbsp;</td>
                      </tr>
                      <tr>
                        <td colspan="3">&nbsp;</td>
                      </tr>
                      <tr>
                        <td height="40" colspan="3"><div align="center">
                            <input name="Send Mail" type="submit" class="small" value="Send Survey" style="color:#000000">
                            <input name="Reset" type="reset" class="small" value="Reset" style="color:#000000">
                          </div></td>
                      </tr>
                    </table>
                  </form>
[/syntax]

Code: Select all

<?

include("functions.php");

//put post variables into easier names, format
$ContactName= formatfield($_POST[ContactName]);
$what= formatfield($_POST[what]);
$most_important= formatfield($_POST[most_important]);
$liked= formatfield($_POST[liked]);
$email= formatfield($_POST[email]);


$message = 
"<B>Name: </B> " . $ContactName . "<BR>\n" .
"<B>My interest in Web conferencing is for:</B> " . $what . "<BR>\n" .
"<B>The Be-Intouch features that are MOST IMPORTANT to me are:</B> " . $most_important . " <BR>\n" .
"<B>The Be-Intouch features that I LIKED the MOST are: </B> " . $liked . "<BR>\n" .
"<B>Email: </B> " . $email . "<BR>\n";



if ($ContactName) {
	//mail the thing
	
	//surround message with html

	$message = 
	"<HTML><HEAD></HEAD><BODY bgcolor= #FFFFFF>\n\n" . 

	$message . "<BR><BR>\n\n" .

	"</FONT></BODY></HTML>";

//create headers

	$headers  = "MIME-Version: 1.0\n";
	$headers .= "Content-type: text/html; charset=iso-8859-1\n";

	/* additional headers */
	$headers .= "FROM: $name <$email>\n";

//send it out
	mail("deblundgren@comcast.net",
	"WebMail: Survey", 
	$message, 
	$headers);


	$redirect= "location: thankyou.html";
	header($redirect);

} else {
	//redirect to oops

	$redirect= "location: oops.html";
	header($redirect);

} ?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Post by thomas777neo »

Your check boxes all have the same name and different values. So when you post the data it will only send one.

Unless you change the check box to something like this:

Code: Select all

<input type="checkbox" name="most_important[]" value="Video">
Notice the [], this makes the value sent an array, you could then use a foreach control structure to iterate through the check boxes.

Code: Select all

foreach ($most_important as $most_imp)
{
    // do something
} // foreach ($most_important as $most_imp)
Post Reply