ahazin Posted January 11, 2008 Share Posted January 11, 2008 Hi guys, i was wondering if you could please help me ive spent like 8h on this and i really cant get it to work and im getting frustrated. Im making a website and on my feedback page i have a forum with 2 text boxes called name_field and email_field then i also have a text area called message. The settings of my fourm are as follows: form name="form1" method="post" action="contact.php" In the contact.php file i have the following code: <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php if(isset($_POST['submit'])) { $to = "lucealmighty@hotmail.co.uk"; $subject = "Please work"; $name_field = $_POST['name']; $email_field = $_POST['email']; $message = $_POST['message']; $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message"; echo "Data has been submitted to $to!"; mail($to, $subject, $body); } else { echo "sorry there has been an error please try again"; ; } ?> </body> </html> What i want is when the user fills in the forum and presses the submit button that the information will get sent to my email address and if so a message is displayed stated it has been submitted otherwise stating there was an error. For the life of me i cant get the code to work and was just wondering if anyone would be so kind as to help me, i would really really appreciate it. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/85553-solved-email-forum-information-please-help/ Share on other sites More sharing options...
revraz Posted January 11, 2008 Share Posted January 11, 2008 What error do you get? You may have to include a FROM: header in your mail() function. Quote Link to comment https://forums.phpfreaks.com/topic/85553-solved-email-forum-information-please-help/#findComment-436593 Share on other sites More sharing options...
ahazin Posted January 11, 2008 Author Share Posted January 11, 2008 i just get a plane white page and no email has been sent to my email address. Thanks for taking the time to respond. Quote Link to comment https://forums.phpfreaks.com/topic/85553-solved-email-forum-information-please-help/#findComment-436596 Share on other sites More sharing options...
revraz Posted January 11, 2008 Share Posted January 11, 2008 Try something like this, create a new .php file and run it. mail("lucealmighty@hotmail.co.uk", "Hi", "This is a test", "FROM: lucealmighty@hotmail.co.uk"); Quote Link to comment https://forums.phpfreaks.com/topic/85553-solved-email-forum-information-please-help/#findComment-436599 Share on other sites More sharing options...
ahazin Posted January 11, 2008 Author Share Posted January 11, 2008 That didnt work either Quote Link to comment https://forums.phpfreaks.com/topic/85553-solved-email-forum-information-please-help/#findComment-436605 Share on other sites More sharing options...
revraz Posted January 11, 2008 Share Posted January 11, 2008 Is this a webhost or a personal server? Is the SMTP info setup in the php.ini? Quote Link to comment https://forums.phpfreaks.com/topic/85553-solved-email-forum-information-please-help/#findComment-436606 Share on other sites More sharing options...
ahazin Posted January 11, 2008 Author Share Posted January 11, 2008 I was simply running it from the c drive but yes plans are on the way to get a server which supports PHP. Judging by what you are saying it would need to be up on the server before it would work. Perhaps I was being stupid thinking it would work from the c drive? Sorry for my stupidity if thats the case lol, im pretty new to PHP. Quote Link to comment https://forums.phpfreaks.com/topic/85553-solved-email-forum-information-please-help/#findComment-436610 Share on other sites More sharing options...
revraz Posted January 11, 2008 Share Posted January 11, 2008 You need a mail server for it to work. Quote Link to comment https://forums.phpfreaks.com/topic/85553-solved-email-forum-information-please-help/#findComment-436611 Share on other sites More sharing options...
ahazin Posted January 11, 2008 Author Share Posted January 11, 2008 So once i purchase the php server and then upload the file it should work correctly? Thanks for the time u spent helping me out. Quote Link to comment https://forums.phpfreaks.com/topic/85553-solved-email-forum-information-please-help/#findComment-436612 Share on other sites More sharing options...
revraz Posted January 11, 2008 Share Posted January 11, 2008 You will probably have to make small changes, but if the webhost supports the mail() function for PHP, you can make it work. Quote Link to comment https://forums.phpfreaks.com/topic/85553-solved-email-forum-information-please-help/#findComment-436613 Share on other sites More sharing options...
ahazin Posted January 11, 2008 Author Share Posted January 11, 2008 cheers for telling me that, was stressing out all day! now i can relax a little. Take it easy and thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/85553-solved-email-forum-information-please-help/#findComment-436614 Share on other sites More sharing options...
ahazin Posted January 14, 2008 Author Share Posted January 14, 2008 Revraz, i got the php server up and running and i got your section of code to email me and work as intended however im still having a little trouble with my own. When i have it hooked up to the code I have in my first page I simply get a page saying "Data has been submitted to !" and nothing ends up in my email address. Was just wondering if you would know what would be causing this problem? Im maybe just doing something stupid and thats why its not working. Quote Link to comment https://forums.phpfreaks.com/topic/85553-solved-email-forum-information-please-help/#findComment-438675 Share on other sites More sharing options...
adam291086 Posted January 14, 2008 Share Posted January 14, 2008 Post the whole code for your mail script. Are you trying to send HTML in the email? Edit Also echo out all the variable to make sure the $_POST has submitted information into your php script Quote Link to comment https://forums.phpfreaks.com/topic/85553-solved-email-forum-information-please-help/#findComment-438678 Share on other sites More sharing options...
ahazin Posted January 14, 2008 Author Share Posted January 14, 2008 <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php if(isset($_POST['submit'])) { $to = "lucealmighty@hotmail.co.uk"; $subject = "Form Tutorial"; $name_field = $_POST['name']; $email_field = $_POST['email']; $message = $_POST['message']; $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message"; echo "Data has been submitted to $to"; mail($to, $subject, $body); } else { echo "Data has been submitted to $to!"; ; } ?> </body> </html> That is the entire code i am using at the minute. Thanks for taking a look. Quote Link to comment https://forums.phpfreaks.com/topic/85553-solved-email-forum-information-please-help/#findComment-438698 Share on other sites More sharing options...
adam291086 Posted January 14, 2008 Share Posted January 14, 2008 try this mail code all on it's own <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); $email = "lucealmighty@hotmail.co.uk"; $subject = "Form Tutorial"; $name = $_POST['name']; $message = "hello, this is a test; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'To: '.$name.' <'.$email.'>,' . "\r\n"; //This is the TO name and Email $headers .= 'From: Adam<lala@lala.com>' . "\r\n"; // This is YOUR name and email $result = mail($email, $subject, $message, $headers); if($result) { echo "Mail has been sent"; } else { echo "Mail Failed"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/85553-solved-email-forum-information-please-help/#findComment-438705 Share on other sites More sharing options...
ahazin Posted January 14, 2008 Author Share Posted January 14, 2008 Thanks for taking the time to right that , with that code i get the following error: Parse error: syntax error, unexpected T_STRING in test.php on line 12 Alternatively i have tried a different type of code: <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php $to = "lucealmighty@hotmail.co.uk"; $subject = "Contact Us"; $name_field = $_REQUEST['name'] ; $email_field = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; $headers = "From: $email_field"; $body = "Name: $name\n E-Mail: $email\n Message:\n $message"; $sent = mail($to, $subject, $body, $headers) ; if($sent) {print "Your mail was sent successfully"; } else {print "We encountered an error sending your mail"; } ?> </body> </html> When i use that code i can get the message section to send to me perfectly but the name_field and email_field dont send. Was wondering if anything stands out which i have not done right? Thanks again for help so far. Appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/85553-solved-email-forum-information-please-help/#findComment-438708 Share on other sites More sharing options...
ahazin Posted January 14, 2008 Author Share Posted January 14, 2008 how stupid was i on a scale of 1 - 10 with my variable names lol. Got it working for now. Thanks alot guys for your effort and input couldnt have got it worken without ur input. Take it easy and thanks. Quote Link to comment https://forums.phpfreaks.com/topic/85553-solved-email-forum-information-please-help/#findComment-438732 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.