silverglade Posted August 4, 2008 Share Posted August 4, 2008 i tried to use mail() to mail a form to my email and its not working, any advice greatly appreciated, extremely appreciated. here is the code. not sure what to do now. derek here is the code to the form which works fine. <html> <head> <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> <title>my first form</title> </head> <body> <form action="myform.php" method="post"> <p>Your Name: <input type="text" name="yourname"><br> E-mail: <input type="text" name="email"></p> <p>Do you like this website? <input type="radio" name="likeit" value="Yes" checked="checked"> Yes <input type="radio" name="likeit" value="No"> No <input type="radio" name="likeit" value="Not sure"> Not sure</p> <p>Your comments:<br> <textarea name="comments" rows="10" cols="40"></textarea></p> <p><input type="submit" value="Send it!"></p> </form> </body> </html> and here is the code to the php page to email the form where i have trouble sending the users data to myself. i only tried to pass "yourname" into $message so far, but im sure i need more variables for the others. <html> <body>Your name is: <?php echo $_POST['yourname']; ?><br /> Your e-mail: <?php echo $_POST['email']; ?><br /> <br />Do you like this website? <?php echo $_POST['likeit']; ?><br /> <br />Comments:<br /> <?php echo $_POST['comments']; ?> <?php // The message $message = 'yourname'; ?> ///HERE IS MY PROBLEM I THINK // In case any of our lines are larger than 70 characters, we should use wordwrap() $message = wordwrap($message, 70); // Send mail('[email protected]', 'My Subject', $message); ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/118040-solved-trying-to-make-this-php-email-form-not-working/ Share on other sites More sharing options...
ratcateme Posted August 4, 2008 Share Posted August 4, 2008 do you have access to the server mail logs is the mail being sent and if you are setting up the server have you setup mail correctly your script looks like it has no problems besides the extra ?> are they in your real script because if they are the php ends at $message = 'yourname'; ?> and the email is never sent Scott. Link to comment https://forums.phpfreaks.com/topic/118040-solved-trying-to-make-this-php-email-form-not-working/#findComment-607259 Share on other sites More sharing options...
silverglade Posted August 4, 2008 Author Share Posted August 4, 2008 here is my new and improved code. and it should work according to the tutorial i used, but it doesnt send the mail. here is the form code that has no problems i THINK. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> <title>my first form</title> </head> <body> <form action="myform.php" method="post"> <p>Your Name: <input type="text" name="yourname"><br> E-mail: <input type="text" name="email"></p> <p>Do you like this website? <input type="radio" name="likeit" value="Yes" checked="checked"> Yes <input type="radio" name="likeit" value="No"> No <input type="radio" name="likeit" value="Not sure"> Not sure</p> <p>Your comments:<br> <textarea name="comments" rows="10" cols="40"></textarea></p> <p><input type="submit" value="submit"></p> </form> </body> </html> and here is my problem php emailer code <html> <body> <?php if(isset($_POST['submit'])) { $to = "[email protected]"; $subject = "Feedback"; $name_field = $_POST['yourname']; $email_field = $_POST['email']; $message = $_POST['likeit']; $comments= $_POST['comments']; $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message\n Comments:\n $comments"; echo "Data has been submitted to $to!"; mail($to, $subject, $body); } else { echo "blarg!"; } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/118040-solved-trying-to-make-this-php-email-form-not-working/#findComment-607278 Share on other sites More sharing options...
revraz Posted August 4, 2008 Share Posted August 4, 2008 Can try to add a 4th parameter, with a FROM: header. Link to comment https://forums.phpfreaks.com/topic/118040-solved-trying-to-make-this-php-email-form-not-working/#findComment-607282 Share on other sites More sharing options...
silverglade Posted August 4, 2008 Author Share Posted August 4, 2008 ok here is code i got to work, its EXTREMELY bare bones, but its all i got up for now and it works. hahah. i will try to build on it some. here is the WORKING form emailer code, very simplified. my google skills are getting better at finding tutorials, knowing the right key phrase is what makes the difference., i googled "php contact form tutorial" and finally it paid off. form code <form method="POST" action="mailer.php"> <input type="text" name="name" size="19"><br> <br> <input type="text" name="email" size="19"><br> <br> <textarea rows="9" name="message" cols="30"></textarea> <br> <br> <input type="submit" value="Submit" name="submit"> </form> and here is the mailer code <?php if(isset($_POST['submit'])) { $to = "[email protected]"; $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 "blarg!"; } ?> : ;D ;D ;D ;D ;D Link to comment https://forums.phpfreaks.com/topic/118040-solved-trying-to-make-this-php-email-form-not-working/#findComment-607288 Share on other sites More sharing options...
malcolm99 Posted August 4, 2008 Share Posted August 4, 2008 Hiya , I just tried this code as I have a similar problem but I get blarg at the end . Does anyone know how to fix posting problems ? Do you have to have special settings your server ?I am running linux or do you have to do somethig else ? Regards Malcolm Link to comment https://forums.phpfreaks.com/topic/118040-solved-trying-to-make-this-php-email-form-not-working/#findComment-607299 Share on other sites More sharing options...
silverglade Posted August 4, 2008 Author Share Posted August 4, 2008 the last post of code i made works. im not sure why it says blarg still for you. but it worked on my web host server. sorry i cant offer any help . derek Link to comment https://forums.phpfreaks.com/topic/118040-solved-trying-to-make-this-php-email-form-not-working/#findComment-607586 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.