Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialmorgan nokringer
3,576 Pointsform 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 :
<p>
<form method="POST" action="traitement.php">
<fieldset>
<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/>
</fieldset>
<fieldset>
<legend>votre message </legend>
<label for="message"> Votre message : </label> <textarea name="message" id="message"> </textarea><br/>
</fieldset>
<input type="submit" value="envoyer le message"/>
and php code is :
<?php
$nom=$HTTP_POST_VARS['nom'];
$mail=$HTTP_POST_VARS['mail'];
$message=$HTTP_POST_VARS['message'];
$subject=$HTTP_POST_VARS['objet'];
/////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
$body="$message";
if (mail($destinataire,$subject,$body,$headers)) {
echo "Votre mail a été envoyé<br>";
} else {
echo "Une erreur s'est produite";
}
?></p>
<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
</a></p>
why didn't i receive the mail?
1 Answer
Ayan Ozturk
3,881 PointsYou need a mail server to be able to use mail() function on PHP. Check this article: https://help.ubuntu.com/community/Postfix for Ubuntu.