Richardb86 Posted January 5, 2009 Share Posted January 5, 2009 I need to create a mail form that collects the Name, Email, Phone Number, and a Message from a person and emails it to my websites mail. So first and foremost I need to know if I need to have anything special on the hosting server, my hosting service is provided by godaddy.com Second I need to know what to place in my html file. Lastly I need to know what i need to place in my php file. Any help is greatly appreciated! and i apologize if this is vauge. This is the code i have in my html file: <div class="bcopy1"> Fill in this section to send us a message, general response time is 24 to 48 hours.<br /><br /> <form id="form1" name="ContactForm" method="post" action="contactus.php"> <label> <span class="ProdName">Name:</span> <br /> <input name="Name" type="text" size="30" maxlength="50" /> </label> <br /> <label> <span class="ProdName">Email: </span><br /> <span class="ProdName"> <input name="Email" type="text" size="30" maxlength="50" /> </span></label> <span class="ProdName"> <label></label> </span><br /> <label> <span class="ProdName">Phone:</span><br /> <input name="phone" type="text" size="30" maxlength="15" /> </label> <br /> <label> <span class="ProdName">Message:: </span><br /> <textarea name="comments" cols="30" rows="5">Please enter questions or comments here.</textarea> </label> <p> <label> <input type="submit" name="Submit" value="Submit" /> </label> <input type="reset" name="Reset" value="Reset" /> </p> </form> This is the code i have in contact.php: <?php $to = $_REQUEST['sendto'] ; $from = $_REQUEST['Email'] ; $fname = $_REQUEST['First Name'] ; $lname = $_REQUEST['Last Name'] ; $headers = "From: $from"; $subject = "Comment from customer $fname $lname"; $fields = array(); $fields{"First Name"} = "First Name"; $fields{"Last Name"} = " Last Name"; $fields{"Email"} = "Email"; $fields{"Phone"} = "Phone"; $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: [email protected]"; $subject2 = "Thank you for contacting us"; $autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.CandiesSecret.com"; if($from == '') {print "You have not entered an email, please go back and try again";} else { if($fname == '') {print "You have not entered a first name, please go back and try again";} else { if($lname == '') {print "You have not entered a last name, 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.candiessecret.com/contactus/thankyou.htm" );} else {header( "Location: http://www.candiessecret.com/contactus/ohno.htm" ); } } } ?> ** moderator if you move this post please send me an email [email protected] and let me know, I am new and I will get lost trying to find it ** Link to comment https://forums.phpfreaks.com/topic/139479-solved-basic-php-mail-form-help/ Share on other sites More sharing options...
bubbasheeko Posted January 5, 2009 Share Posted January 5, 2009 Skimming quickly, what you have looks okay. Have you tried it? Received any errors? Link to comment https://forums.phpfreaks.com/topic/139479-solved-basic-php-mail-form-help/#findComment-729634 Share on other sites More sharing options...
Richardb86 Posted January 5, 2009 Author Share Posted January 5, 2009 I have tested it, and the only result i receive is that the browser attempts to open contact.php when you click the submit button. Link to comment https://forums.phpfreaks.com/topic/139479-solved-basic-php-mail-form-help/#findComment-729641 Share on other sites More sharing options...
Richardb86 Posted January 5, 2009 Author Share Posted January 5, 2009 The code i have in my html page is actually as follows: <form method=post action="contact.php"> <div class="bcopy1"> Fill in this section to send us a message, general response time is 24 to 48 hours. <table width="484" align="center"> <tr> <td colspan="2"><strong>Contact us using this form:</strong></td> </tr> <tr> <td width="184" align="right">Concerning:</td> <td width="288" align="left"><select name="sendto"> <option value="[email protected]">General</option> <option value="[email protected]" selected="selected">Support</option> <option value="[email protected]">Sales</option> <option value="[email protected]">Shipping</option> </select></td> </tr> <tr> <td width="184" align="right"><font color="red">*</font>First name:</td> <td width="288" align="left"><input size="48" name="First Name" /></td> </tr> <tr> <td width="184" align="right"><font color="red">*</font>Last name:</td> <td width="288" align="left"><input size="48" name="Last Name" /></td> </tr> <tr> <td width="184" align="right"><font color="red">*</font> Email:</td> <td width="288" align="left"><input size="48" name="Email" /></td> </tr> <tr> <td width="184" align="right">Phone:</td> <td width="288" align="left"><input size="48" name="Phone" /></td> </tr> <tr> <td width="184" align="right" valign="top">Message:</td> <td width="288" align="left"><div class="comfix"><textarea name="textarea" cols="39" rows="10"></textarea></div></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" name="send" value="Submit" /> <input type="reset" name="reset" value="Reset" /></td> </tr> <tr> <td colspan="2" align="center"><small>A <font color="red">*</font> indicates a field is required</small></td> </tr> </table> </div> </form></td> </tr> </table> </div> Link to comment https://forums.phpfreaks.com/topic/139479-solved-basic-php-mail-form-help/#findComment-729650 Share on other sites More sharing options...
bubbasheeko Posted January 5, 2009 Share Posted January 5, 2009 No message at all? hmmm Try printing the variables from contact.php to screen...add an echo $variable . "<br>" after each variable. See where it fails that way. You are using an array, my mail script doesn't use them. That is the only subtle difference that I see from your code to my own. Link to comment https://forums.phpfreaks.com/topic/139479-solved-basic-php-mail-form-help/#findComment-729651 Share on other sites More sharing options...
bubbasheeko Posted January 5, 2009 Share Posted January 5, 2009 Your html is fine, it is contact.php that has the issue. So you can ignore it for now. Focus on checking the variables in the contact.php and see where it stops. Link to comment https://forums.phpfreaks.com/topic/139479-solved-basic-php-mail-form-help/#findComment-729652 Share on other sites More sharing options...
Richardb86 Posted January 5, 2009 Author Share Posted January 5, 2009 is their anything that I should have on my server to make php work? or does it work inherently? as for the stuff you recommended i do, my knowledge of php is to limited to do that, this is a borrowed script that I edited to match my needs. perhaps you could give me an example of the code you are talking about? Link to comment https://forums.phpfreaks.com/topic/139479-solved-basic-php-mail-form-help/#findComment-729653 Share on other sites More sharing options...
Richardb86 Posted January 5, 2009 Author Share Posted January 5, 2009 I changed the code in contact.php to this, and now it always goes to the error out page uhoh.htm: <?php $to = $_REQUEST['sendto'] ; $from = $_REQUEST['Email'] ; $name = $_REQUEST['Name'] ; $headers = "From: $from"; $subject = "Comment from customer $name"; $fields = array(); $fields{"Name"} = "Name"; $fields{"Email"} = "Email"; $fields{"Phone"} = "Phone"; $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: [email protected]"; $subject2 = "Thank you for contacting us"; $autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.CandiesSecret.com"; if($from == '') {print "You have not entered an email, please go back and try again";} else { if($name == '') {print "You have not entered a first name, 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.candiessecret.com/contactus/thankyou.htm" );} else {header( "Location: http://www.candiessecret.com/contactus/ohno.htm" ); } } } ?> and I changed the html page to mirror these changes. Link to comment https://forums.phpfreaks.com/topic/139479-solved-basic-php-mail-form-help/#findComment-729670 Share on other sites More sharing options...
bubbasheeko Posted January 5, 2009 Share Posted January 5, 2009 This is what I use every once and a while. It works. Obviously sub what you need sub'd. $strFrom="[email protected]"; $strTo = $_POST['department_email']; $strSubject= $_POST['subject']; $strContent='<!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>Example</title> <link href="http://www.example.com/css/email.css" rel="stylesheet" type="text/css" /> </head> <body> <div class="outer_container"> <div class="title"></div> <div class="main_container"> <div class="content"> <div class="main_header_top"></div> <div class="main_header_middle"> <div class="main_header_middle_text">' . $_POST['subject'] . '</div> </div> <div class="main_header_bottom"></div> <div class="main_content"> <div class="main_inner_content">' . $_POST['message'] . '</div> </div> <div class="main_footer"></div> </div> </div> </div> </body> </html>'; if(mail($strTo,$strSubject,$strContent,"From:$strFrom\r\nReply-to: $strFrom\r\nContent-type: text/html; charset=us-ascii")) { if($_GET['option'] == "2") { $sendmail_message = 'Your message was sent successfully. Thank you for taking the time to contact us.'; } else { $sendmail_message = 'Your message was sent successfully.'; } } else { $sendmail_message = 'There was an error processing your message.'; } Link to comment https://forums.phpfreaks.com/topic/139479-solved-basic-php-mail-form-help/#findComment-729679 Share on other sites More sharing options...
Richardb86 Posted January 5, 2009 Author Share Posted January 5, 2009 This generates a html page for the email? I need it to just be plain text. I'm so new to php that I can't even get this to work, and you know it works! Link to comment https://forums.phpfreaks.com/topic/139479-solved-basic-php-mail-form-help/#findComment-729680 Share on other sites More sharing options...
bubbasheeko Posted January 5, 2009 Share Posted January 5, 2009 Just take out everything in the content variable. You can just type in plain text. It will still be sent as an html email, but even people who receive text emails will be able to view it with no troubles. Link to comment https://forums.phpfreaks.com/topic/139479-solved-basic-php-mail-form-help/#findComment-729694 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.