Rugbyspelare Posted December 7, 2018 Share Posted December 7, 2018 Hello! i am new to php. I need help to get all the displayed information in the mail, see below. I dont get the phone information. Thanks in adwansed <?php // anger en variabel som kan lagra de eventuella felaktigheterna $errors = array(); // kontrollera om ett Förnamn angivits if (!$_POST["namn"]) $errors[] = "- NAMN"; // kontrollera om ett TELEFONNUMMER angivits if (!$_POST["phone"]) $errors[] = "- TELEFONNUMMER"; // kontrollera om ett TELEFONNUMMER angivits $emailcheck = $_POST["email"]; if(!preg_match("/^[a-z0-9\å\ä\ö._-]+@[a-z0-9\å\ä\ö.-]+\.[a-z]{2,6}$/i", $emailcheck)) $errors[] = "- din E-POSTADRESS saknas eller är felaktig"; // kontrollera om ett Meddelande angivits if (!$_POST["message"]) $errors[] = "- inget MEDDELANDE har skrivits!"; if (count($errors)>0){ echo "<h1>Felmeddelande:</h1> <strong>Följande information måste anges innan du kan skicka formuläret:</strong><br /><br> "; foreach($errors as $fel) echo "$fel <br />"; echo "<br />Ange den information som saknas och skicka formuläret igen. Tack! <br />"; echo "<a href='javascript:history.go(-1)'>klicka här för att komma tillbaka till formuläret</a>"; } else { // formuläret är korrekt ifyllt och informationen bearbetas $to = "mailo@mail.com"; $from = $_POST["email"]; $subject = 'Kontakt från webbplatsen!'; $namn = $_POST["namn"]; $phone = $_POST["phone"]; $message = $_POST["message"]; ######################################################################## // HEADERS för innehållstyp och textkodning $headers = "Content-Type: text/plain; charset=utf-8 \r\n"; $headers .= "From:".$namn." <".$from.">"."\r\n"; $headers .= "MIME-Version: 1.0 \r\n"; ######################################################################## // Mailfunktionen som skickar bekräftelsen if (mail($to, $subject, $message, $headers)) echo nl2br("<h2>Tack $namn! Ditt meddelande har skickats!</h2> //###I WANT ALL THIS IN THE MAIL### <b>Mottagare:</b> $to <b>Namn:</b> $namn <b>E-Mail:</b> $from <b>Telefonnummer:</b> $phone <b>meddelande:</b> <br/>$message "); else echo "Det gick inte att skicka ditt meddelande"; } ?> Quote Link to comment Share on other sites More sharing options...
benanamen Posted December 7, 2018 Share Posted December 7, 2018 (edited) Your error checking logic is wrong. If you submit a proper form the POST fields will always be set (except unchecked checkboxes) so they will always be in the POST array and your error checks will never run. You need to trim the POST array, then check for empty. You need to compose the body of the email with the expected variables. Right now the message only contains the message field. Post your form code here while your at it.. Edited December 7, 2018 by benanamen 1 Quote Link to comment Share on other sites More sharing options...
ginerjm Posted December 8, 2018 Share Posted December 8, 2018 As pointed out above you are saying that you want certain data in the message, but you don't PUT IT IN THE MESSAGE. Also - you want to show the message as an HTML message but your headers state you are sending a "text/plain" email. Fix this and as benanamen says fix the input checking and you will have a good bit of code here. 1 Quote Link to comment Share on other sites More sharing options...
Rugbyspelare Posted December 8, 2018 Author Share Posted December 8, 2018 Thanks for the tips. I will change to html. Here is the form code: <form name="kontaktform" id="kontaktform" method="post" action="formmail.php" enctype="multipart/form-data"> <fieldset> <h2>Meddelande</h2> <label for="namn">Namn:</label> <br /> <input name="namn" id="namn" class="input_text" type="text" /> <br /> <label for="email">E-postadress:</label> <br /> <input name="email" id="email" class="input_text" type="text" /> <br /> <label for="phone">Telefonnummer:</label> <br /> <input name="phone" id="phone" class="input_text" type="text" /> <br /> <label for="message">Meddelande:</label> <br /> <textarea name="message" id="message" class="input_text" content-type="text" cols="30" rows="5"></textarea> <br /> <input name="send" id="send" class="send_button" value="Skicka meddelandet" type="submit" /> </fieldset> Thanks in advansed. Quote Link to comment Share on other sites More sharing options...
benanamen Posted December 9, 2018 Share Posted December 9, 2018 You are not uploading files so there is no reason to use enctype="multipart/form-data" . Just leave out the enctype and it will use the default. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted December 9, 2018 Share Posted December 9, 2018 You now have a form (missing a </form> tag) so what is next on improving your process? Changing the PHP code perhaps to handle the inputs better? Quote Link to comment 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.