FORM:发件人姓名而不是电子邮件。

FORM: Name as sender instead of e-mail.

我有一个非常基本的表单,它使用 PhpMail 发送它的内容,但是有什么方法可以将表单的 "sender name" 从电子邮件地址更改为姓名。

示例: 而不是 "from: form.ello@whatever.org" 它说 "From: Ello Recruitment" 或其他什么。

这是我目前使用的代码:

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\r\n";
$headers = 'From: Ello Recruitment' . "\r\n" .
'Reply-To: xxx@whatever.org' . "\r\n" .
'X-Mailer: PHP/' . phpversion();


$body = "$description_field\n";


echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.whatever.org\">";
mail($to, $subject, $body, $headers);
} else {
echo "not working";
}
?>

Marcel 快到了 - 您需要更改 From header:

$headers = 'From: Ello Recruitment <form.ello@whatever.org>' . "\r\n" .

您可能无法在某些服务器上设置发件人地址,例如 gmail 不允许您任意设置。

我建议您使用库从 PHP 发送电子邮件,因为它会为您正确格式化所有这些。