Jump to content

Dont get all information in the mail.


Rugbyspelare

Recommended Posts

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";

} 

?>

 

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.