形式:姓名作为发件人,而不是电子邮件



我有一个非常基本的表单,使用PhpMail来发送它的内容,但是有没有办法将表单的"发件人名称"从电子邮件地址更改为名称?

的例子:而不是"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-8rn";
$headers = 'From: Ello Recruitment' . "rn" .
'Reply-To: xxx@whatever.org' . "rn" .
'X-Mailer: PHP/' . phpversion();

$body = "$description_fieldn";

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

Marcel就快完成了-你需要改变From标题:

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

在某些服务器上设置发件人地址可能会遇到麻烦,例如gmail不允许你任意设置发件人地址。

我建议你使用一个库来从PHP发送邮件,因为它会为你正确地完成所有这些格式化。

最新更新