我已经创建了一个PHP电子邮件flooder,它工作正常。但是,在测试时,我只是将发件人的电子邮件地址作为名称。我想要的是发件人的姓名。
以下是代码。
是的,有人能帮帮我吗?感谢...<?php
$to = $_POST['to'];
$from = $_POST['ot'];
$subject = $_POST['tema'];
$message = $_POST['message'];
$headers .= "From: ".$from;
if ($_POST['radio']==="plain")
{
$headers = "Content-type: text/plain; charset=UTF-8 \r\n";
$headers .= "From: ".$from;
}
elseif ($_POST['radio']==="html")
{
$headers = "Content-type: text/html; charset=UTF-8 \r\n";
$headers .= "From: ".$from;
}
mail($to, $subject, $message, $headers);
?>
答案 0 :(得分:1)
尝试这样的事情:
$headers .= "From: Name of the sender <".$from.">";
答案 1 :(得分:0)
假设表单有一个名为“realname”的输入字段,则会编写以下代码:
<?php
$to = $_POST['to'];
$from = $_POST['ot'];
$name = $_POST['realname'];
$subject = $_POST['tema'];
$message = $_POST['message'];
if ($_POST['radio']==="plain")
{
$headers .= "Content-type: text/plain; charset=UTF-8 \r\n";
}
elseif ($_POST['radio']==="html")
{
$headers .= "Content-type: text/html; charset=UTF-8 \r\n";
}
$headers .= "From: $name <$from>";
mail($to, $subject, $message, $headers);
?>