首页 > 解决方案 > 为什么我的 PHP 表单在我的电子邮件客户端中显示不同的名称?

问题描述

所以我有两个非常相似的表格,一个是联系表,另一个是工作申请表。两者都有以下片段,告诉服务器 SMTP 地址;

$email_from = "$first $surname, <SMTP Server Address>@azure.com";

两种表格都工作得很好,但是,与我的联系表格相关的 PHP 文档显示了发件人的名字和姓氏(根据“$first $surname”变量的指示) - 根据需要 - 但是,从工作申请网站收到的电子邮件表单只显示(在电子邮件客户端收件箱中)CGI 邮件服务器名称。不显示发件人的名字和姓氏。

为什么,当两个表单具有完全相同的 PHP 代码时,在电子邮件客户端中显示的内容却有不同的结果?

它完全违背逻辑。

职位申请表

<?php
if($_POST['submit'] && isset($_FILES['attachment'])){

$title = $_POST['title'];
$first = $_POST['first'];
$surname = $_POST['surname'];
$depotPreference = $_POST['depotPreference'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$address3 = $_POST['address3'];
$address4 = $_POST['address4'];
$email = $_POST['email'];
$number = $_POST['number'];
$drivinglicence = $_POST['drivinglicence'];
$dvlacheckcode = $_POST['dvlacheckcode'];
$userMessage = $_POST['userMessage'];
$RightToWork = $_POST['RightToWork'];
/*$dobdd = $_POST['dobdd'];
$dobmm = $_POST['dobmm'];
$dobyyyy = $_POST['dobyyyy'];
$nin = $_POST['nin'];*/

$email_from = "$first $surname, xxxx@azure.com";

$Password = 'xxxx';

$email_subject = "You have a new NOD application from $first $surname.";

$email_body = 
    "User title: $title. \n".       
    "User First Name: $first.\n".
    "User Surname Name: $surname. \n".
    "Depot Preference: $depotPreference.\n".
    "House Name / Number: $address1. \n".
    "Street Name: $address2. \n".
    "Town / City: $address3. \n".
    "Post Code: $address4. \n".
    "User email: $email. \n".
    "User Contact Number: $number.\n".
    "Right to work in the UK: $RightToWork. \n".
    "Last 8 digits of drivers licence number: $drivinglicence.\n".
    "DVLA Check Code: $dvlacheckcode.\n".
    /*"Applicants Date of Birth: $dobdd / $dobmm / $dobyyyy.\n".
    "Applicants National Insurance Number: $nin.\n".*/
    "Applicants prior experience: $userMessage.\n".
    "If this is an application for a DA, please confirm all information is correct by going to https://www.viewdrivingrecord.service.gov.uk/driving-record/validate?_ga=2.194915242.60848212.1571236007-425916386.1568197951..
    \n";

    $to = 'xxxx, xxxx, xxxx';

    $headers = "From: $email_from \r\n";

    $headers ="Reply to: $first $surname \r\n";

    mail($to,$email_subject,$email_body, $headers);

    header('Location: xxxx');
//}
?>

标准联系表

<?php

$department = $_POST['department'];   
$title = $_POST['title'];
$first = $_POST['first'];
$surname = $_POST['surname'];
$email = $_POST['email'];
$number = $_POST['number'];
$attachment = $$_POST['attachment'];
$userMessage = $_POST['userMessage'];

foreach ($_FILES["attachment"]["name"] as $k => $v) {
$mail->AddAttachment( $_FILES["attachment"]["tmp_name"][$k],    $_FILES["attachment"]["name"][$k] );
 }


$email_from = "$first $surname, xxxx@azure.com";

$Password = 'xxxx';

$email_subject = "Website enquiry from $first $surname.";

$email_body = 
"User title: $title. \n".
"The department this message is for is: $department.\n".
"User First Name: $first.\n".
"User Surname Name: $surname. \n".
"User email: $email.\n".
"User Contact Number: $number.\n".
"File: $attachment.\n".
"User Message is: $userMessage.\n";

$headers = "From: $email_from" . "\r\n" . "Bcc: xxx, xxx, xxx" . "\r\n" . "Reply to: $first $surname";

/*$headers ="Reply to: $first $surname \r\n";*/

mail($to,$email_subject,$email_body, $headers, $attachment);

header('Location xxxxx');

?>

标签: phphtmlformssmtp

解决方案


推荐阅读