cmbcorp Posted April 10, 2008 Share Posted April 10, 2008 hi, i have recently made a contact us page and it all looks ok, but im having troubles and getting error messages. I have 3 files: sendmail.php Which has the following code: <?php $to = $_REQUEST['sendto'] ; $from = $_REQUEST['Email'] ; $name = $_REQUEST['Name'] ; $headers = "From: $from"; $subject = "XICG.COM - Customer Referral Form"; $fields = array(); $fields{"Name"} = "Name"; $fields{"Company"} = "Company"; $fields{"Email"} = "Email"; $fields{"Phone"} = "Phone"; $fields{"Name1"} = "Referral Name"; $fields{"Company1"} = "Referral Company"; $fields{"Email1"} = "Referral Email"; $fields{"Phone1"} = "Referral Phone"; $fields{"Message"} = "Additional Comments"; $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $headers2 = "From: referral@xicg.com.au"; $subject2 = "Thank you for your referral"; $autoreply = "Thank you for for your query. A sales representitive will be in contact with you shortly!."; if($from == '') {print "You have not entered an email, please go back and try again";} else { if($name == '') {print "You have not entered a name, please go back and try again";} else { if($phone == '') {print "You have not entered a phone number, please go back and try again";} else { if($company == '') {print "You have not entered a company name, please go back and try again";} else { if($company1 == '') {print "You have not entered a company name, please go back and try again";} else { if($email1 == '') {print "You have not entered a email address, please go back and try again";} else { if($phone1 == '') {print "You have not entered a phone number, please go back and try again";} else { if($name1 == '') {print "You have not entered a 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.xicg.com.au/referral/thankyou.html" );} else {print "We encountered an error sending your mail, please notify referral@xicg.com.au"; } } } ?> i then have my contact form page with the following code: <!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=iso-8859-1" /> <title>xicg.com - customer referral form</title> </head> <body> <a href="http://www.xicg.com/"><img src="xicg.gif" alt="XICG.COM" border="0" /></a> <form method="post" action="sendmail.php"> <table width="400" align="center"> <tr> <td colspan="2"><div align="center"> <p align="left"> </p> </div></td> </tr> <tr> <td><strong>Your Information </strong></td> <td> </td> </tr> <tr> <td><div align="left">Department:</div></td> <td><div align="left"> <select name="sendto"> <option value="sales@xicg.com">Referral Department</option> </select> </div></td> </tr> <tr> <td><div align="left"><font color="red">*</font> Name:</div></td> <td><input size="25" name="Name" /></td> </tr> <tr> <td><div align="left"><font color="red">*</font> Email:</div></td> <td><input size="25" name="Email" /></td> </tr> <tr> <td><div align="left"><font color="red">*</font> Company:</div></td> <td><input size="25" name="Company" /></td> </tr> <tr> <td><div align="left"><font color="red">*</font> Phone:</div></td> <td><input size="25" name="Phone" /></td> </tr> <tr> <td height="23"><div align="left"><strong>Your Referral </strong></div></td> <td height="23"> </td> </tr> <tr> <td height="23"><div align="left"><font color="red">*</font> Name: </div></td> <td height="23"><input size="25" name="Name1" /></td> </tr> <tr> <td height="23"><div align="left"><font color="red">*</font> Email:</div></td> <td height="23"><input size="25" name="Email1" /></td> </tr> <tr> <td height="23"><font color="red">*</font> Company:</td> <td height="23"><input size="25" name="Company1" /></td> </tr> <tr> <td height="23"><font color="red">*</font> Phone:</td> <td height="23"><input size="25" name="Phone1" /></td> </tr> <tr> <td colspan="2" align="center"><div align="left"><strong>Additional Comments: </strong></div></td> </tr> <tr> <td colspan="2" align="center"><div align="left"> <textarea name="Message" rows="5" cols="50"></textarea> </div></td> </tr> <tr> <td colspan="2" align="center"><div align="left"> <input type="submit" name="send" value="Submit" /> </div></td> </tr> <tr> <td colspan="2" align="center"><div align="left"><small>A <font color="red">*</font> indicates a field is required</small></div></td> </tr> </table> </form> </body> </html> and finally i have my thankyou.html which works fine. everytime i fill out my form i get the following error message: Parse error: syntax error, unexpected $end in /home/xicgca/public_html/referral/sendmail.php on line 50 Im not sure what im doing wrong in the sendmail script. Could someone please assist me with this? i would really appriciate it. thanks. regards, jason. Quote Link to comment Share on other sites More sharing options...
Cosizzle Posted April 10, 2008 Share Posted April 10, 2008 and $end error tends to many you have to many or to little closing brackets somewhere. Its hard to read the way you structured it, but it looks like you have an extra one at the end of the script. Quote Link to comment Share on other sites More sharing options...
cmbcorp Posted April 10, 2008 Author Share Posted April 10, 2008 thanks for your reply. i have tried a few different combinations of removing those end brackets.. still no go.. any ideas guys? cheers jason. Quote Link to comment Share on other sites More sharing options...
Cosizzle Posted April 11, 2008 Share Posted April 11, 2008 Looking at it again you seemed to be not closing your else statements... <?php $to = $_REQUEST['sendto'] ; $from = $_REQUEST['Email'] ; $name = $_REQUEST['Name'] ; $headers = "From: $from"; $subject = "XICG.COM - Customer Referral Form"; $fields = array(); $fields{"Name"} = "Name"; $fields{"Company"} = "Company"; $fields{"Email"} = "Email"; $fields{"Phone"} = "Phone"; $fields{"Name1"} = "Referral Name"; $fields{"Company1"} = "Referral Company"; $fields{"Email1"} = "Referral Email"; $fields{"Phone1"} = "Referral Phone"; $fields{"Message"} = "Additional Comments"; $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $headers2 = "From: referral@xicg.com.au"; $subject2 = "Thank you for your referral"; $autoreply = "Thank you for for your query. A sales representitive will be in contact with you shortly!."; if($from == '') { print "You have not entered an email, please go back and try again"; } else { //do something } if($name == '') { print "You have not entered a name, please go back and try again"; } else { //do something } if($phone == '') { print "You have not entered a phone number, please go back and try again"; } else { //do something } if($company == '') { print "You have not entered a company name, please go back and try again"; } else { //do something } if($company1 == '') { print "You have not entered a company name, please go back and try again"; } else { //do something } if($email1 == '') { print "You have not entered a email address, please go back and try again"; } else { //do something } if($phone1 == '') { print "You have not entered a phone number, please go back and try again"; } else { //do something } if($name1 == '') { print "You have not entered a 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.xicg.com.au/referral/thankyou.html" ); } else { print "We encountered an error sending your mail, please notify referral@xicg.com.au"; } ?> I really rushed looking over this cause im headed out the office but theoretically that 'should' work... its a start at least Quote Link to comment Share on other sites More sharing options...
cmbcorp Posted April 11, 2008 Author Share Posted April 11, 2008 thanks for your help. i tried your code and the following error message appears: You have not entered a phone number, please go back and try againYou have not entered a company name, please go back and try againYou have not entered a company name, please go back and try againYou have not entered a email address, please go back and try againYou have not entered a phone number, please go back and try againYou have not entered a name, please go back and try again Warning: Cannot modify header information - headers already sent by (output started at /home/xicgca/public_html/referral/sendmail.php:41) in /home/xicgca/public_html/referral/sendmail.php on line 77 Quote Link to comment Share on other sites More sharing options...
Cosizzle Posted April 11, 2008 Share Posted April 11, 2008 I had these two scripts kicking around from who knows when. But they do what your asking for. contact.htm <html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>New Page 1</title> </head> <body> <form method="POST" action="mailer.php"> Name: <input type="text" name="name" size="19"><br> <br> E-Mail: <input type="text" name="email" size="19"><br> <br> <input type="checkbox" name="check[]" value="blue_color"> Blue<br> <input type="checkbox" name="check[]" value="green_color"> Green<br> <input type="checkbox" name="check[]" value="orange_color"> Orange<br> <br> <input type="radio" value="yes" name="radio"> YES<br> <input type="radio" value="no" name="radio"> NO <br> <br> <select size="1" name="drop_down"> <option>php</option> <option>xml</option> <option>css</option> <option>html</option> </select><br> <br> Message:<br> <textarea rows="9" name="message" cols="30"></textarea><br> <br> <input type="submit" value="Submit" name="submit"> </form> </body> </html> mailer.php <?php if(isset($_POST['submit'])) { $to = "youaddress@youremail.com"; $subject = "Form"; $name_field = $_POST['name']; $email_field = $_POST['email']; $message = $_POST['message']; $option = $_POST['radio']; $dropdown = $_POST['drop_down']; foreach($_POST['check'] as $value) { $check_msg .= "Checked: $value\n"; } $body = "From: $name_field\n E-Mail: $email_field\n $check_msg Option: $option\n Drop-Down: $dropdown\n Message:\n $message\n"; echo "Data has been submitted to $to!"; mail($to, $subject, $body); } else { echo "blarg!"; } ?> Quote Link to comment Share on other sites More sharing options...
doni49 Posted April 11, 2008 Share Posted April 11, 2008 I was going to point out the issue about the brackets. But besides that....... You should really validate what the user enters before sending the message. If I were to visit your form, I could type the following in the "From field". "doni49@mydomain.com\r\nBCC:spamRecipient1@hotmail.com,spamRecipient2@hotmail.com" If I did that I would be using your server to send spam. Now it's not like someone would actully sit there and type that in. But it would be really simple to write a script that would access your form and fill in that data. Quote Link to comment Share on other sites More sharing options...
cmbcorp Posted April 11, 2008 Author Share Posted April 11, 2008 thanks once again for your help.. really appriciate it. i will give it a try later. just need to know what im doing wrong with my script to avoid this in the future. can anyone else help on this? thanks... Quote Link to comment Share on other sites More sharing options...
Cosizzle Posted April 11, 2008 Share Posted April 11, 2008 To check email address, ive done this up... again grabbed from something else thats been written so work it in. //Check email address $emailCheck= $_POST['email1']; if(!empty($_POST['email1'])) { if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $emailCheck)) { $errors[] = 'That is not a valid E-Mail Address.'; } }else { $errors[] = 'There was no E-Mail Address.'; } Quote Link to comment Share on other sites More sharing options...
cmbcorp Posted April 11, 2008 Author Share Posted April 11, 2008 thanks doni for your input, ill keep that in mind.. Quote Link to comment Share on other sites More sharing options...
doni49 Posted April 11, 2008 Share Posted April 11, 2008 I haven't looked it all over yet--but in the beginning, you are trying to set array values with curly braces instead of brackets. $fields = array(); $fields{"Name"} = "Name"; $fields{"Company"} = "Company"; $fields{"Email"} = "Email"; $fields{"Phone"} = "Phone"; $fields{"Name1"} = "Referral Name"; $fields{"Company1"} = "Referral Company"; $fields{"Email1"} = "Referral Email"; $fields{"Phone1"} = "Referral Phone"; $fields{"Message"} = "Additional Comments"; should be $fields = array(); $fields["Name"] = "Name"; $fields["Company"] = "Company"; $fields["Email"] = "Email"; $fields["Phone"] = "Phone"; $fields["Name1"] = "Referral Name"; $fields["Company1"] = "Referral Company"; $fields["Email1"] = "Referral Email"; $fields["Phone1"] = "Referral Phone"; $fields["Message"] = "Additional Comments"; Quote Link to comment Share on other sites More sharing options...
doni49 Posted April 11, 2008 Share Posted April 11, 2008 ok. I looked through the entire thing and that's all I see as far as bracket issues. But as written (I'm looking at the original code), if the name field is not empty--even if every other field IS EMPTY--the mail function will attempt to run. Due yourself a favor--before all of your if statements, set a boolean to true. Then the first time a field doesn't validate correctly set that variable to false. Put the mail functions in a separate if statement--if the boolean is TRUE send the messages. If the boolean is false, DON'T send the messages. Quote Link to comment Share on other sites More sharing options...
cmbcorp Posted April 11, 2008 Author Share Posted April 11, 2008 doni, i did what you suggested: <?php $to = $_REQUEST['sendto'] ; $from = $_REQUEST['Email'] ; $name = $_REQUEST['Name'] ; $headers = "From: $from"; $subject = "XICG.COM - Customer Referral Form"; $fields = array(); $fields{"Name"} = "Name"; $fields{"Company"} = "Company"; $fields{"Email"} = "Email"; $fields{"Phone"} = "Phone"; $fields{"Name1"} = "Referral Name"; $fields{"Company1"} = "Referral Company"; $fields{"Email1"} = "Referral Email"; $fields{"Phone1"} = "Referral Phone"; $fields{"Message"} = "Additional Comments"; $body = "We have received the following information:\n\n"; foreach($fields as $a => $b) { $body.=sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $headers2 = "From: noreply@xicg.com.au"; $subject2 = "Thank you for contacting us"; $autoreply = "Thank you for for your referral."; if($from=='') {print "You have not entered an email, please go back and try again";} if($Name=='') {print "You have not entered a name, please go back and try again";} if($Phone=='') {print "You have not entered a phone number, please go back and try again";} if($Company=='') {print "You have not entered a company name, please go back and try again";} if($Name1=='') {print "You have not entered a company name, please go back and try again";} if($Phone1=='') {print "You have not entered a company name, please go back and try again";} if($Email1=='') {print "You have not entered a company name, please go back and try again";} if($Company1=='') {print "You have not entered a company 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.xicg.com.au/referral/thankyou.html"); } else { echo "We encountered an error sending your mail, please notify sales@xicg.com"; } } ?> Now if you dont fill in the fields, it displays the error messages, but still sends the mail.. error: You have not entered a company name, please go back and try againYou have not entered a company name, please go back and try again Warning: Cannot modify header information - headers already sent by (output started at /home/xicgca/public_html/referral/sendmail.php:33) in /home/xicgca/public_html/referral/sendmail.php on line 44 any ideas? jase. Quote Link to comment Share on other sites More sharing options...
doni49 Posted April 11, 2008 Share Posted April 11, 2008 That code has the same effect and is not what I was suggesting. This is more along the lines of what I was suggesting. And don't forget this does nothing to validate the code. $autoreply = "Thank you for for your referral."; $validForm = TRUE; if($from=='') {print "You have not entered an email, please go back and try again"; $validForm = false;} if($Name=='') {print "You have not entered a name, please go back and try again";$validForm = false;} if($Phone=='') {print "You have not entered a phone number, please go back and try again"; $validForm = false;} if($Company=='') {print "You have not entered a company name, please go back and try again"; $validForm = false;} if($Name1=='') {print "You have not entered a company name, please go back and try again"; $validForm = false;} if($Phone1=='') {print "You have not entered a company name, please go back and try again"; $validForm = false;} if($Email1=='') {print "You have not entered a company name, please go back and try again"; $validForm = false;} if($Company1=='') {print "You have not entered a company name, please go back and try again"; $validForm = false;} if ($validForm){ $send = mail($to, $subject, $body, $headers); $send2 = mail($from, $subject2, $autoreply, $headers2); if($send) { header("Location: http://www.xicg.com.au/referral/thankyou.html"); } else { echo "We encountered an error sending your mail, please notify sales@xicg.com"; } } } What we're doing is assuming that every thing is ok and then the first time a problem is found, we change the test var to reflect that. Quote Link to comment Share on other sites More sharing options...
doni49 Posted April 11, 2008 Share Posted April 11, 2008 error: You have not entered a company name, please go back and try againYou have not entered a company name, please go back and try again Warning: Cannot modify header information - headers already sent by (output started at /home/xicgca/public_html/referral/sendmail.php:33) in /home/xicgca/public_html/referral/sendmail.php on line 44 any ideas? jase. As to the headers already sent error, I don't see where you're sending headers. Take a look at reply #10 above. I have no idea what effect this issue would have--but I know it won't work right. It might be causing strange issues. Quote Link to comment Share on other sites More sharing options...
cmbcorp Posted April 11, 2008 Author Share Posted April 11, 2008 mate your a great help! thanks.. Quote Link to comment Share on other sites More sharing options...
doni49 Posted April 11, 2008 Share Posted April 11, 2008 NP Glad to see you got it working. Have fun! Quote Link to comment Share on other sites More sharing options...
doni49 Posted April 11, 2008 Share Posted April 11, 2008 ok. I looked through the entire thing and that's all I see as far as bracket issues. But as written (I'm looking at the original code), if the name field is not empty--even if every other field IS EMPTY--the mail function will attempt to run. Do yourself a favor--before all of your if statements, set a boolean to true. Then the first time a field doesn't validate correctly set that variable to false. Put the mail functions in a separate if statement--if the boolean is TRUE send the messages. If the boolean is false, DON'T send the messages. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.