atchy Posted January 11, 2007 Share Posted January 11, 2007 Hi Everyone,I am still a newcomer to PHP and have with a lot of help got my site up and running. My last problem is getting the results of a form sent back by email. My test form submits ok but I do not receive the email. Looking at all the tutorials it looks easy using the mail() function.Can anyone please help. John Quote Link to comment https://forums.phpfreaks.com/topic/33803-sending-results-of-form-by-email-using-php/ Share on other sites More sharing options...
SweetLou Posted January 11, 2007 Share Posted January 11, 2007 Well, there could be a couple of reasons for this, your code is wrong, you don't have sendmail or equivalent, if you do have them, can PHP use them? Let's look at your code first. Quote Link to comment https://forums.phpfreaks.com/topic/33803-sending-results-of-form-by-email-using-php/#findComment-158696 Share on other sites More sharing options...
ardyandkari Posted January 12, 2007 Share Posted January 12, 2007 ok...it connects now........THANKS to all who have helped out!!! it is super appreciated. ;Dnow...i tried the form, it comes back with no errors, which i assume means that everything went well. but when i check the database, it doesn't show that there are any records. does it take some time for the entries to get put into the database? i took all the code from a tutorial page, so i was assuming that everything worked until i was directed to a syntax error earlier...thanks in advance...ardy Quote Link to comment https://forums.phpfreaks.com/topic/33803-sending-results-of-form-by-email-using-php/#findComment-158801 Share on other sites More sharing options...
atchy Posted January 12, 2007 Author Share Posted January 12, 2007 Hi Thanks for the replyCode as requestedThis is from a tutorial found on apptools.com while googling. It all seems to work apart from receiving email. I sent it to my work address which is a different system (First Class) and arrived ok. Sendmail is set up.Hope you can help.ThanksJohn[code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><html><head><title>Contact Form</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body><?php if ($_SERVER['REQUEST_METHOD'] != 'POST'){ $me = $_SERVER['PHP_SELF'];?> <form name="form1" method="post" action="<?php echo $localhost;?>"> <table border="0" cellspacing="0" cellpadding="2"> <tr> <td>Name:</td> <td><input type="text" name="Name"></td> </tr> <tr> <td>Subject</td> <td><input type="text" name="Subject"></td> </tr> <tr> <td valign="top">Message:</td> <td><textarea name="MsgBody"></textarea></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Send"></td> </tr> </table></form><?php } else {// initialize a variable to // put any errors we encounter into an array $errors = array(); // test to see if the form was actually // posted from our form $page = $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; // check to see if a name was entered if (!$_POST['Name']) // if not, add that error to our array $errors[] = "Name is required"; // check to see if a subject was entered if (!$_POST['Subject']) // if not, add that error to our array $errors[] = "Subject is required"; // check to see if a message was entered if (!$_POST['MsgBody']) // if not, add that error to our array $errors[] = "Message body is required"; // if there are any errors, display them if (count($errors)>0){ echo "<strong>ERROR:<br>\n"; foreach($errors as $err) echo "$err<br>\n"; } else { // no errors, so we build our message $recipient = '[email protected]'; $from = stripslashes($_POST['Name']); $subject = stripslashes($_POST['Subject']); $msg = "Message sent by $from\n ".stripslashes($_POST['MsgBody']); if (mail($recipient,$subject,$msg)) echo "Thanks for your message!"; else echo "An unknown error occurred."; } }?></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33803-sending-results-of-form-by-email-using-php/#findComment-159240 Share on other sites More sharing options...
SweetLou Posted January 12, 2007 Share Posted January 12, 2007 I am confused, you said it worked when sending to your work address but it is not receiving. This script does not receive email, it sends it. Do you mean that when you put the address to send the email to is your work address, it works, but when it is your other email address, no email shows up in your inbox? Maybe a spam filter is catching it then. The code looks fine, well, I mean it looks functional. As for security, you have some major security holes in that code. Quote Link to comment https://forums.phpfreaks.com/topic/33803-sending-results-of-form-by-email-using-php/#findComment-159492 Share on other sites More sharing options...
atchy Posted January 13, 2007 Author Share Posted January 13, 2007 Sorry meant to say, receiving the email at my work address but not my home address. I checked the spam filters and there was nothing there. I appeciate that it is not secure but this is not the final code all I am trying to do is get the basics to work first. John Quote Link to comment https://forums.phpfreaks.com/topic/33803-sending-results-of-form-by-email-using-php/#findComment-159921 Share on other sites More sharing options...
SweetLou Posted January 13, 2007 Share Posted January 13, 2007 Well, if you are receiving email at work, then the script works. I would have no idea why you are not receiving at your home address, unless it is in the your spam box or if you typed the address wrong or if your home address breaks the script. But, since it is going to your work address, nothing is wrong with the script. Quote Link to comment https://forums.phpfreaks.com/topic/33803-sending-results-of-form-by-email-using-php/#findComment-159922 Share on other sites More sharing options...
atchy Posted January 13, 2007 Author Share Posted January 13, 2007 Thanks thats reassuring to know. Will now look elsewhereJohn Quote Link to comment https://forums.phpfreaks.com/topic/33803-sending-results-of-form-by-email-using-php/#findComment-159926 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.