Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


morgan nokringer
morgan nokringer
3,576 Points

form for send an email

i need your help i can't receive any mail with this form et the sending php mail code

the form is like that :

 <form method="POST" action="traitement.php">
 <legend> vos coordonnées </legend>
    <label for="nom"> Votre nom : </label><input type="text" name="nom" id="nom" size="30" maxlength="20" placeholder="votre nom"/> <br/>
    <label for="mail"> Votre email : </label><input type="email" name="mail" id="mail" size="28" maxlength="50" placeholder="ex : exemple@mail.com"/><br/>
    <legend>votre message </legend>
    <label for="message"> Votre message : </label> <textarea name="message" id="message"> </textarea><br/>
    <input type="submit" value="envoyer le message"/>

and php code is :


/////voici la version Mine 
$headers = "MIME-Version: 1.0\r\n"; 

//////ici on détermine le mail en format text 
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n"; 

////ici on détermine l'expediteur et l'adresse de réponse 
$headers .= "From: $nom <$mail>\r\nReply-to : $nom <$mail>\nX-Mailer:PHP";

$subject='message de dream valley chapter';
$destinataire="nokringer.morgan@gmail.com"; //remplacez "webmaster@votre-site.com" par votre adresse e-mail
if (mail($destinataire,$subject,$body,$headers)) { 
echo "Votre mail a été envoyé<br>"; 
} else { 
echo "Une erreur s'est produite"; 
<p align="center">Vous allez bientot etre redirigé vers la page d'acceuil<br>
Si vous n'etes pas redirigé au bout de 5 secondes cliquez <a href="contact.php">ici 

why didn't i receive the mail?

1 Answer

You need a mail server to be able to use mail() function on PHP. Check this article: https://help.ubuntu.com/community/Postfix for Ubuntu.