How can I add a "sender name" in a PHP contact form? -


considering experience php limited, customised contact form found , works want. thing that's bothering me can't find way include "sender name" in it, means when recieve e-mail, sender field empty seen below.

enter image description here

i set "contato" sender name. possible?

any tips on how achieve appreciated.

php:

<?php if($_post) {     //check if ajax request, exit if not     if(!isset($_server['http_x_requested_with']) , strtolower($_server['http_x_requested_with']) != 'xmlhttprequest') {         die();     }       $to_email       = "giovanna.coppola@yahoo.com"; //replace recipient email address     $subject        = 'formul&#225;rio de contato (site)'; //subject line emails      //check $_post vars set, exit if missing     if(!isset($_post["username"]) || !isset($_post["useremail"]) || !isset($_post["userphone"]) || !isset($_post["usermessage"]))     {         die();     }      //sanitize input data using php filter_var().     $user_name        = filter_var($_post["username"], filter_sanitize_string);     $user_email       = filter_var($_post["useremail"], filter_sanitize_email);     $user_phone       = filter_var($_post["userphone"], filter_sanitize_string);     $user_message     = filter_var($_post["usermessage"], filter_sanitize_string);      //additional php validation     if(strlen($user_name)<6) // if length less 6 throw http error.     {         header('http/1.1 500 nome muito curto ou campo vazio.');         exit();     }     if(!filter_var($user_email, filter_validate_email)) //email validation     {         header('http/1.1 500 insira um e-mail va&#769;lido.');         exit();     }     if(!is_numeric($user_phone)) //check entered data numbers     {         header('http/1.1 500 esse campo so&#769; aceita n&#250;meros.');         exit();     }     if(strlen($user_message)<10) //check emtpy message     {         header('http/1.1 500 mensagem curta demais.');         exit();     }      //proceed php email.     $headers = 'from: '.$user_email.'' . "rn" .     'reply-to: '.$user_email.'' . "rn" .     'x-mailer: php/' . phpversion();      $message = 'nome: '.$user_name."\r\n".            'e-mail: '.$user_email."\r\n".            'telefone: '.$user_phone."\r\n".            'mensagem: '.$user_message;  $sentmail = mail($to_email, $subject, $message, $headers);      if(!$sentmail)     {         header('http/1.1 500 n&#227;o foi poss&#237;vel enviar. tente novamente.');         exit();     }else{         echo 'ol&#225;, '.$user_name.'. agradecemos o contato! ';         echo 'retornaremos o mais breve poss&#237;vel.';     } } ?> 

change

$headers = 'from: '.$user_email.'' . "rn" . 

to

$headers = 'from: '.$user_name.' <'.$user_email. '>'. "\r\n" . 

see example #4 in manual mail() - http://www.php.net/manual/en/function.mail.php#example-3416


Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -