FORM:作为发件人而不是电子邮件的名称。

时间:2015-05-25 08:03:36

标签: php html forms phpmailer

我有一个非常基本的表单,它使用PhpMail发送它的内容但是有一些方法可以改变发送者名称"从电子邮件地址到名称的形式。

实施例: 而不是"来自:form.ello@whatever.org"它说"来自: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";
}
?>

1 个答案:

答案 0 :(得分:0)

马塞尔几乎就在那里 - 您需要更改From标题:

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

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

我建议您使用库从PHP发送电子邮件,因为它会正确地为您进行格式化。