I have this code, that is supposed to send a mail to an address. The problems is: in the header i’m supposed to get the name like “Bob Marley” for instance, but it says “(unknown sender)” if the name is greater then one word. If the name is exactly one word, it works. If i concatenate the $_POST[‘nume’] value to the $message, it’s all there. For some reason, in the header, it does not work like it should.
<form name="contact" method="post" class="clearfix" id="formular">
<input class="inputC" type="text" placeholder="Full Name" id="numeCo" onClick="clearValue(this.id)" onBlur="testValue(this.id)" name="nume"/>
<input class="inputC" type="text" placeholder="E-mail Address" id="adresaCo" onClick="clearValue(this.id)" onBlur="testValue(this.id)" name="adrMail"/>
<input class="inputC" type="text" placeholder="What services do you need?" id="serviciiCo" onClick="clearValue(this.id)" onBlur="testValue(this.id)" name="servicii"/>
<div class="sumarise">
<textarea class="textAreaC" placeholder="Please summarize your project..." id="textArCo" onClick="clearValue(this.id)" onBlur="testValue(this.id)" name="descriere"></textarea>
</div>
<div class="sB clearfix">
<input class="submitC" type="submit" value="Send Message" />
</div>
</form>
<?php
if(isset($_POST['nume'], $_POST['adrMail'], $_POST['descriere']))
{
/*echo "<script> return checkForm();</script>";*/
$to = "radu.mircea.andrei@gmail.com";
$subject = $_POST['servicii'];
$message = $_POST['descriere'];
$name = $_POST['nume'];
$headers= "From: ".$name."\n".'Reply-To: '.$_POST['adrMail'];
mail($to,$subject,$message,$headers);
}
?>
I am going to put this as answer because I think it is quite important for you to note.
There is a vulnerability when using the
mail()function as you are with user definedFromheaders. See this question here: Proper prevention of mail injection in PHPHowever to solve your actual problem: