我正在为网站写一个html / php电子邮件表单。 php工作正常,但在电子邮件标题的“发件人:”字段的电子邮件端看起来像“Tomemxample@email.com”,当我希望它看起来像“Tom,example @email.com”。我是新手使用PHP所以我可能会遗漏一些语法明智的东西。
<?php
function spamcheck($field) {
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
if(filter_var($field, FILTER_SANITIZE_EMAIL)) {
return TRUE;
} else {
return FALSE;
}
}
$name = test_input($_POST['name']);
$email = test_input($_POST['email']);
$subject = test_input($_POST['subject']);
$message = test_input($_POST['message']);
$to = "email goes here";
$send = mail($to, $subject, $message, "From: " .$name .$email);
if ($send) {
header ("Location: http:// refreshes the page");
} else {
echo "The form could not be sent, please contact me at: email goes here";
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
答案 0 :(得分:0)
将电子邮件地址放在“&lt;”之间和“&gt;”如下:
$send = mail($to, $subject, $message, "From:". $name ."<".$email.">". "\r\n");
答案 1 :(得分:0)
答案 2 :(得分:0)
只需在名称和电子邮件之间添加逗号:)
$send = mail($to, $subject, $message, "From: " . $name . ", " . $email);
应该是这样的:
$send = mail($to, $subject, $message, "From: " . $name . "<" . $email . ">");
结帐