Cathryn Posted June 23, 2011 Share Posted June 23, 2011 Hello, I am a beginner and i am trying to send an email that shows what weather the person experienced from information they fill out on a form. This is the form: <html> <body> <form method="post" action="email.php"> <p><h2>How is your weather now?</h2></p> <p>Please enter your information: </p> <p> City:<input type="text" name="city"> Month:<input type="text" name="month"> Year:<input type="text" name="year"> </p> <p>Please choose the kinds of weather you experienced from the list below.<br> Choose all that apply.</p> <p> <input type="checkbox" value="Sunshine" name="type[]">Sunshine<br> <input type="checkbox" value="Clouds" name="type[]">Clouds<br> <input type="checkbox" value="Rain" name="type[]">Rain<br> <input type="checkbox" value="Hail" name="type[]">Hail<br> <input type="checkbox" value="Sleet" name="type[]">Sleet<br> <input type="checkbox" value="Snow" name="type[]">Snow<br> <input type="checkbox" value="Wind" name="type[]">Wind<br> <input type="checkbox" value="Cold" name="type[]">Cold<br> <input type="checkbox" value="Heat" name="type[]">Heat<br> <input type="checkbox" value="Fog" name="type[]">Fog<br> <input type="checkbox" value="Humidity" name="type[]">Humidity </p> Anything Else? Please list in the additional weather conditions in box, separated by commas.<br> <input type="text", name="add" size="50"><br> <input type=submit name="submit" value="Go"> </form> </body> </html> and here is the email coding: <?php if(isset($_POST['email'])) { $email_to = "[email protected]"; $email_subject = "<h1>How is your weather now</h1>"; $city = $_POST['city']; $month = $_POST['month']; $year = $_POST['year']; $type = $_POST['type']; $add = $_POST['add']; $email_message .= "In ".clean_string($city) . " in the month of " .clean_string($month).clean_string($year)." you observed the following weather: ""\n"; <?php $check =0; $top = array('Sunshine', 'Clouds', 'Rain', 'Hail', 'Sleet', 'Snow', 'Wind', 'Cold', 'Heat', 'Fog', 'Humidity'); foreach ($_POST['type'] as $type){ echo "<li>$type</li> \r\n"; } ?> // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include your own success html here --> Thank you for contacting us. We will be in touch with you very soon. <?php } ?> I keep getting errors on the part where i put the message body of the email. Any help would be greatly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/240181-smtp-email/ Share on other sites More sharing options...
Alex Posted June 23, 2011 Share Posted June 23, 2011 Please use [[/tt]code] or [[tt]php] tags to post code in the future. Is that exactly how the code appears in your file? Your PHP tags are all messed up. You shouldn't have a "<?php" when you're already inside of a PHP tag. Similarly, you houldn't be using "?>" if you're not intending to get out of PHP. If that's not your problem, what exactly are the errors you're getting? Quote Link to comment https://forums.phpfreaks.com/topic/240181-smtp-email/#findComment-1233713 Share on other sites More sharing options...
Cathryn Posted June 23, 2011 Author Share Posted June 23, 2011 After fixing the tags, the problem is mainly the logic to allow the email to send what the user as put inside the form. The $email_message string is giving errors hence i cannot email the form results to the user. Quote Link to comment https://forums.phpfreaks.com/topic/240181-smtp-email/#findComment-1233721 Share on other sites More sharing options...
TeNDoLLA Posted June 23, 2011 Share Posted June 23, 2011 So what errors are you getting then ? And have you defined the headers for the email? What does clean_string() do? Quote Link to comment https://forums.phpfreaks.com/topic/240181-smtp-email/#findComment-1233722 Share on other sites More sharing options...
Alex Posted June 23, 2011 Share Posted June 23, 2011 It looks like you're trying to append to the string using the .= operator without the string being defined beforehand. If so, you should change that to just $email_message = ... Quote Link to comment https://forums.phpfreaks.com/topic/240181-smtp-email/#findComment-1233724 Share on other sites More sharing options...
Cathryn Posted June 23, 2011 Author Share Posted June 23, 2011 Even after removing the clean_string() and using the $email_message code is not working. $email_message = "In ".$city . " in the month of " . $month.$year." you observed the following weather: ""\n"; $check =0; $top = array('Sunshine', 'Clouds', 'Rain', 'Hail', 'Sleet', 'Snow', 'Wind', 'Cold', 'Heat', 'Fog', 'Humidity'); foreach ($_POST['type'] as $type){ echo "<li>$type</li> \r\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/240181-smtp-email/#findComment-1233732 Share on other sites More sharing options...
Alex Posted June 23, 2011 Share Posted June 23, 2011 You have an extra two "" now. $email_message = "In ".$city . " in the month of " . $month.$year." you observed the following weather: \n"; If that fails, you're still not telling us the error. And you're still not using [[tt][/tt]code] tags. Quote Link to comment https://forums.phpfreaks.com/topic/240181-smtp-email/#findComment-1233733 Share on other sites More sharing options...
Cathryn Posted June 23, 2011 Author Share Posted June 23, 2011 Its working now, thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/240181-smtp-email/#findComment-1233754 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.