Bongeh Posted December 5, 2007 Share Posted December 5, 2007 Hi there, i'm fairly new to php but im kinda trying to jump in at the deep end, ive got a script which should do what i want but it doenst send the email to the address, the page does definitly use the script though because when the submit button on the form is pressed it forwards you to the thankyou page, which is only specified within the php mail script. In the dir i have 'mailform.php' <?php if(isset($_POST['Submitted'])) { $Errors = Array(); if(!trim($_POST['firstname'])) $Errors[] = "First name"; if(!trim($_POST['lastname'])) $Errors[] = "Last name"; if(!trim($_POST['subject'])) $Errors[] = "Subject"; if(!trim($_POST['comment'])) $Errors[] = "Comment"; if(!preg_match("/[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9]{2,4}/",$_POST['eaddress'])) $Errors[] = "e-mail missing (Is the format correct?)"; if(strtolower(trim($_POST['antispam'])) != "seven") $Errors[] = "Type the word 'seven' in lower case letters"; if(!count($Errors)) { $SendTo = "test@test.com"; $Subject = "Querie"; $FromString = "From: ".$_POST['eaddress']."\r\n"; $Indhold = "The following was submitted:\r\n\r\n"; $Indhold .= "firstname: ".$_POST['firstname']."\r\n"; $Indhold .= "lastname: ".$_POST['lastname']."\r\n"; $Indhold .= "e-mail: ".$_POST['eaddress']."\r\n"; $Indhold .= "phone: ".$_POST['phone']."\r\n"; $Indhold .= "subject: ".$_POST['subject']."\r\n\r\n"; $Indhold .= "comment:\r\n".preg_replace("(\r\n|\r|\n)","\r\n",$_POST['comment'])."\r\n"; $MailSuccess = mail($SendTo,$Subject,$Indhold,$FromString); header("Location: /thankyou.html"); exit; } } ?> on the php page with the form on i have.. <?php require_once("mailform.php") ; ?> On the top line and... <?php if(isset($Errors) && is_array($Errors) && count($Errors)) { echo "<div style=\"padding:10px\">"; echo '<p class="required">The following fields are missing: </p>'."\n"; echo '<p class="required">'."\n"; foreach($Errors as $Error) echo $Error.' *<br />'."\n"; echo '</p>'."\n"; echo "</div>"; } if(isset($MailSuccess)) { if(!$MailSuccess) { echo '<p class="required">There was an unexpected error. Please try later</p>'."\n"; } } ?> The error messages work correctly on the form page when fields aren't filled in or the email format is wrong, and when as said above the submit button is pushed it uses the mailform to forward to the thankyou page, so im assuming something on mailform.php is incorrect. Sorry if im alittle incoherent, any help at all would be greatly appreciated. Thank you in advance. P.s. I'm aware that test@test.com isnt my email, ive changed it for the purposes of posting the code. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 5, 2007 Share Posted December 5, 2007 PHP really doesn't know if the mail made it out of the mail server or not. Assuming your webhost alows mail() to run? Maybe your ISP is blocking the mail as spam? You could try just a simple one line mail() statement with the required data just to see if it goes through or not. But according to your code, there is nothing stopping the Thankyou page from appearing after you hit submit. Quote Link to comment Share on other sites More sharing options...
Bongeh Posted December 5, 2007 Author Share Posted December 5, 2007 my hosting is setup correctly i used a simpler mail script to test and the email went through almost instantaneously. The 'mailform.php' script isn't sending the mail, yet it goes through to the thankyou page after submitting. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 5, 2007 Share Posted December 5, 2007 And it will if you look at your code because the only condition that thankyou needs is if the form is submitted. The 'mailform.php' script isn't sending the mail, yet it goes through to the thankyou page after submitting. Quote Link to comment Share on other sites More sharing options...
Bongeh Posted December 5, 2007 Author Share Posted December 5, 2007 nono im not sure if im explaining it correctly, when i click submit, it goes onto the thankyou page, but it doesnt send the mail. So the script should be working, but it isnt.. Sorry if im talking in circles im really confused. Quote Link to comment Share on other sites More sharing options...
Schlo_50 Posted December 5, 2007 Share Posted December 5, 2007 I think what revraz means is, you have no validation in your script. If you click submit your browser will go the the thankyou page regardless of whether the script is outputting anything because there basically isn't any code to say "if script runs incorrectly then don't redirect to thankyou page." Which infact is exactly what Revrav was saying. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 5, 2007 Share Posted December 5, 2007 You are explaining it correctly. The issue is that you seem to think that since your thankyou page appears that it should be sending the mail, but if you look at your code that isn't the case. The only condition your thankyou page needs is if you hit submit. So don't use that as a indication that your mail should be sent. Try this, strip all the excess code out of the page. Just put 4 variables in the page ($to, $subject, $message, $from), then send the mail. See if that works. If so, add some of your code back in, one variable at a time and then test. Quote Link to comment Share on other sites More sharing options...
Bongeh Posted December 5, 2007 Author Share Posted December 5, 2007 oh sorry for the misunderstanding. I managed to fix the problem however. i put ini_set("sendmail_from", "test@test.com"); into the mailform.php Something to do with the hosting server being windows. Thank you very much revraz and schlo, i've only just joined this community and started learning php but will try to help others where i can thank you for your time! 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.