FORM:作为发件人而不是电子邮件的名称。
问题描述:
I have a very basic form that uses PhpMail to send it's content but is there some way to change the "sender name" of the form from an e-mail adress to a name.
Example: Instead of "from: form.ello@whatever.org" it says "From: Ello Recruitment" or whatever.
Here's the code i'm currently using:
HTML:
<form name="10_percent" action="http://www.whatever.org/recruit.php" method="post" style="text-align:center;">
<label for="description"><p>Description</p></label>
<textarea name="description" id="description" rows="4" cols="50"></textarea>
<input type="submit" id="submit" name="submit" value="Send" style="width:88px; height:24px;"/>
</form>
PHP:
<?php
if(isset($_POST['submit'])) {
$to = "xxx@whatever.org";
$subject = "Recruitment";
$epost_field = $_POST['description'];
$headers = "Content-type: text/html; charset=utf-8
";
$headers = 'From: Ello Recruitment' . "
" .
'Reply-To: xxx@whatever.org' . "
" .
'X-Mailer: PHP/' . phpversion();
$body = "$description_field
";
echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.whatever.org\">";
mail($to, $subject, $body, $headers);
} else {
echo "not working";
}
?>
答
Marcel was nearly there - you need to change the From
header:
$headers = 'From: Ello Recruitment <form.ello@whatever.org>' . "
" .
You may have trouble setting the From address on some servers, for example gmail doesn't let you do this arbitrarily.
I would recommend you use a library to send email from PHP as it will do all this kind for formatting for you correctly.