xxghostbusterxx Posted June 26, 2009 Share Posted June 26, 2009 Please check the following: THE FORM: <div id="content" style="height:440px; padding-top: 50px;"> <form action="formmail.php" method="post" id="enquiryform"> <fieldset style="width: 300px; padding-top: 8px; margin-bottom: 0px; margin-left:87px; padding-bottom:20px"> <legend>Your contact details</legend> <p style="width:300px;"> <label for="name">Name:</label> <input type="text" name="name" id="name" tabindex="1" /> </p> <p style="width:300px;"> <label for="email">Email:</label> <input type="text" name="email" id="email" tabindex="2" /> </p> <p style="width:300px;"> <label for="telephone">Telephone:</label> <input type="text" name="telephone" id="telephone" tabindex="3" /> </p> </fieldset> <fieldset style="width: 300px; padding-top: 0px; margin-left:87px; padding-bottom:20px"> <legend>Comments</legend> <p style="width:300px;"> <label for="message">Message:</label> <textarea name="message" id="message" rows="10" cols="20" tabindex="4"></textarea> </p> </fieldset> <input class="button" type='submit' value='Submit' style="margin-left:300px;" /> </form> </div> THE PHP SCRIPT: <?php /* Incoming Subject and Email Variables - Fixed */ $emailSubject = 'Message'; $webMaster = 'joebloggs@hotmail.com'; /* Gathering Data Variables - User Data */ $name = $_POST['name']; $email = $_POST['email']; $telephone = $_POST['telephone']; $message = $_POST['message']; $body = <<<EOD <br><hr><br> Email: $email <br> Name: $name <br> Telephone: $telephone <br> Comments: $message <br> EOD; $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); /* Results rendered as code */ $theResults = <<<EOD Removed for this post (too much data to post) EOD; echo "$theResults" ?> You can see the form at www.beechhillsafety.co.uk. The data gets sent off, the thank you page appears, but nothing arrives at my mail box. This is stranmge as it worked for ages and now does nothing; could it be a problem with the server host? Thanks in advance for any help. Quote Link to comment https://forums.phpfreaks.com/topic/163752-php-form-details-not-arriving-at-mail-box/ Share on other sites More sharing options...
blaatschaap Posted June 26, 2009 Share Posted June 26, 2009 <?php if($_SERVER['REQUEST_METHOD'] == "POST"){ /* Incoming Subject and Email Variables - Fixed */ $emailSubject = 'Message'; $webMaster = 'joebloggs@hotmail.com'; /* Gathering Data Variables and checks if valid - User Data */ $name = $_POST['name']; $email = $_POST['email']; $telephone = $_POST['telephone']; $message = $_POST['message']; if(!preg_match("^/[a-z0-9]$/i", $name)){ $msg = "Name did contain illegal characters"; } elseif(!preg_match("/^.+@.+\..+$/", $email)){ $msg = "Email is not valid"; }else { $body = "<br><hr><br> Email: $email <br> Name: $name <br> Telephone: $telephone <br> Comments: $message"; $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); if($success){ $msg = "Mail have been sended"; } /* Shows the message/error */ if($msg){ echo $msg; } } } ?> <div id="content" style="height:440px; padding-top: 50px;"> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="enquiryform"> <fieldset style="width: 300px; padding-top: 8px; margin-bottom: 0px; margin-left:87px; padding-bottom:20px"> <legend>Your contact details</legend> <p style="width:300px;"> <label for="name">Name:</label> <input type="text" name="name" id="name" tabindex="1" /> </p> <p style="width:300px;"> <label for="email">Email:</label> <input type="text" name="email" id="email" tabindex="2" /> </p> <p style="width:300px;"> <label for="telephone">Telephone:</label> <input type="text" name="telephone" id="telephone" tabindex="3" /> </p> </fieldset> <fieldset style="width: 300px; padding-top: 0px; margin-left:87px; padding-bottom:20px"> <legend>Comments</legend> <p style="width:300px;"> <label for="message">Message:</label> <textarea name="message" id="message" rows="10" cols="20" tabindex="4"></textarea> </p> </fieldset> <input class="button" type='submit' value='Submit' style="margin-left:300px;" /> </form> </div> I adjusted the code abit and made it more secure. Quote Link to comment https://forums.phpfreaks.com/topic/163752-php-form-details-not-arriving-at-mail-box/#findComment-864031 Share on other sites More sharing options...
xxghostbusterxx Posted June 26, 2009 Author Share Posted June 26, 2009 Thanks for the reply. However, I am trying to keep the following included to display the thankyou html. /* Results rendered as code */ $theResults = <<<EOD Removed for this post (this is the HTML that will display) EOD; echo "$theResults"; I got this code from http://www.tutvid.com/tutorials/dreamweaver/tutorials/phpFormHandler.php Everything seems to be coded correctly. I am baffled. Quote Link to comment https://forums.phpfreaks.com/topic/163752-php-form-details-not-arriving-at-mail-box/#findComment-864044 Share on other sites More sharing options...
soycharliente Posted June 26, 2009 Share Posted June 26, 2009 The PHP mail() function returns a boolean value. Capture the returned result in a variable and see what it is. At least knowing what value the function is returning is a step in the right direction. <?php $to = "email@example.com"; $subject = "Testing the form"; $message = "Hello World."; $bool = mail($to, $subject, $message); echo $bool; ?> Also, if you wrap your posted code in the code tags (click the pound sign on the formatting toolbar), it will display better for the rest of us. Quote Link to comment https://forums.phpfreaks.com/topic/163752-php-form-details-not-arriving-at-mail-box/#findComment-864051 Share on other sites More sharing options...
blaatschaap Posted June 26, 2009 Share Posted June 26, 2009 The PHP mail() function returns a boolean value. Capture the returned result in a variable and see what it is. At least knowing what value the function is returning is a step in the right direction. <?php $to = "email@example.com"; $subject = "Testing the form"; $message = "Hello World."; $bool = mail($to, $subject, $message); echo $bool; ?> Also, if you wrap your posted code in the code tags (click the pound sign on the formatting toolbar), it will display better for the rest of us. don't forget the $header else the mail will arrive at spam ~Blaatschaap Quote Link to comment https://forums.phpfreaks.com/topic/163752-php-form-details-not-arriving-at-mail-box/#findComment-864055 Share on other sites More sharing options...
xxghostbusterxx Posted June 26, 2009 Author Share Posted June 26, 2009 The result was 1 What does this mean? Do I have a server side problem with the mailto function? Quote Link to comment https://forums.phpfreaks.com/topic/163752-php-form-details-not-arriving-at-mail-box/#findComment-864059 Share on other sites More sharing options...
soycharliente Posted June 26, 2009 Share Posted June 26, 2009 It means that it evaluated as TRUE. So you know that the mail function IS executing properly. Did you double check the spelling of the email address you're sending to? Could it be something as simple as a typo? Quote Link to comment https://forums.phpfreaks.com/topic/163752-php-form-details-not-arriving-at-mail-box/#findComment-864060 Share on other sites More sharing options...
xxghostbusterxx Posted June 26, 2009 Author Share Posted June 26, 2009 I have tried two email addresses; bot fail to get delivered... Quote Link to comment https://forums.phpfreaks.com/topic/163752-php-form-details-not-arriving-at-mail-box/#findComment-864064 Share on other sites More sharing options...
soycharliente Posted June 26, 2009 Share Posted June 26, 2009 Put this at the top of the page, make sure that the page WON'T forward when you submit the form, and check to see if all the information that is being submitted is actually being fed to the page. This will show you everything in the POST array. <?php print_r($_POST); ?> Quote Link to comment https://forums.phpfreaks.com/topic/163752-php-form-details-not-arriving-at-mail-box/#findComment-864066 Share on other sites More sharing options...
xxghostbusterxx Posted June 26, 2009 Author Share Posted June 26, 2009 Correction: Have received two Hello World emails to my work address Have received nothing from hotmail...(even though it was working perfectly well a couple of weeks ago) A big clue I think... Quote Link to comment https://forums.phpfreaks.com/topic/163752-php-form-details-not-arriving-at-mail-box/#findComment-864069 Share on other sites More sharing options...
blaatschaap Posted June 26, 2009 Share Posted June 26, 2009 Correction: Have received two Hello World emails to my work address Have received nothing from hotmail...(even though it was working perfectly well a couple of weeks ago) A big clue I think... well maybe it isn't.. perhaps server where you run it at got blocked by hotmail. this will happend quite quickly if you send rapid emails try gmail.com ~Blaatschaap Quote Link to comment https://forums.phpfreaks.com/topic/163752-php-form-details-not-arriving-at-mail-box/#findComment-864071 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.