irnbru1984 Posted September 15, 2009 Share Posted September 15, 2009 Hey there, Sorry if this is a bit of a newbie type question but I have written a simple on line form with an email function and I can not seem to get it working. Can anyone shed some light on why it isnt working. In an ideal world I want people to fill in the form and if all works well to be redirected to a thank you page (thankyou.php) and if it doesn't work to (sorry.php) and as a side not I have a selector in the form for choosing if the person wants to get a weekly newsletter. If the answer yes I need a second email to be sent to someone else but if they select no then it is not to be sent. Hope that all makes sense. Thanks! THE FORM <form method="post" action="contact2.php"> <table bgcolor=#cccccc align=center> <tr><td colspan=2><strong>Newsletter Request Form:</strong></td></tr> <tr><td class="form_text">Title:</td><td><input size=25 name="Title"></td></tr> <tr><td class="form_text">First Name<font color=red>*</font>:</td><td><input size=25 name="FirstName" /></td></tr> <tr><td class="form_text">Last Name<font color=red>*</font>:</td><td><input size=25 name="LastName" /></td></tr> <tr><td class="form_text">Company Name<font color=red>*</font>:</td><td><input size=25 name="CompanyName" /></td></tr> <tr><td class="form_text">E-Mail:</td><td><input size=25 name="EMail"></td></tr> <tr><td class="form_text">Contact Phone Number:</td><td><input size=25 name="ContactPhoneNumber"></td></tr> <tr><td class="form_text">Would you like to receive our Newsletter:</td> <td valign="top"> <select name="Newsletter"> <option value="Yes">Yes Please</option> <option value="No">No Thank You</option> </select> </td> </tr> <tr><td colspan=2 align=center><input type=submit name="send" value="Submit"></td></tr> <tr><td colspan=2 align=center class="form_text"><small><font color=red>*</font> indicates a field is required</small></td></tr> </table> </form> THE PROCESS CODE <?php $from = $_REQUEST['EMail'] ; $name = $_REQUEST['FirstName'] ; $headers = "From: $from"; $subject = "Newsletter Request Form"; $fields = array(); $fields{"Title"} = "Title"; $fields{"FirstName"} = "First Name"; $fields{"LastName"} = "Last Name"; $fields{"CompanyName"} = "Company Name"; $fields{"EMail"} = "E-Mail"; $fields{"ContactPhoneNumber"} = "Contact Phone Number"; $fields{"Newsletter"} = "Send Client Newsletter"; $body = "The following information has been sent to us through the website:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $headers2 = "From: [email protected]"; $subject2 = "Thank you for sending us your information"; $autoreply = "Thank you for sending us your information. Somebody will get back to you as soon as possible. If you have any more questions, please consult our website"; $send = mail("[email protected]", $subject, $body, $headers); $send2 = mail($from, $subject2, $autoreply, $headers2); if($fields{"Newsletter"} == 'Yes') { mail("[email protected]", $subject, $body, $headers);} if($send) { header('Location:http://www.myurl.co.uk/thankyou.php');} else { header('Location:http://www.myurl.co.uk/sorry.php');} } } ?> Link to comment https://forums.phpfreaks.com/topic/174312-simple-e-mailer-scrpit-i-can-not-get-working/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.