我想在提交 HTML 表单时使用 PHP 发送电子邮件。
我从教程中学习并制作了这个 PHP 脚本,但是当我在我的网络邮件中查看它时,我只看到电子邮件地址、主题和消息,但没有看到名称。我需要做什么才能显示名称?
表单变量:
if (empty($_POST) === false) {
$errors = array();
$name = trim($_POST["name"]);
$email = trim($_POST["email"]);
$subject = trim($_POST["subject"]);
$message = trim($_POST["message"]);
$answerbox = trim($_POST["answerbox"]);
// ... etc (validation)
if (empty($errors) === true) {
$headers = 'From: '.$email. "\r\n" . $name.
'Reply-To: '.$email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail('mail@example.com',$subject,$message,$headers);
print "<p class='formerrors'>Thank you for your message, I'll get back to you shortly!</p>";
}