我想擁有它,因此當用戶發送表單時,主題行顯示用戶名稱,如「來自[用戶名稱]的查詢」。它現在如何設置,它的主題是「從站點聯繫表單」。我如何修改代碼來實現這一點?聯繫人表單名稱字符串
<?php
// configure
$from = '[email protected]';
$sendTo = '[email protected]';
$subject = 'Contact form at site';
$fields = array('name' => 'Name', 'surname' => 'Surname', 'phone' => 'Phone', 'email' => 'Email', 'message' => 'Message'); // array variable name => Text to appear in email
$okMessage = 'Your Message was successfully submitted. Thank you! We will get back to you soon.';
$errorMessage = 'There was an error while submitting the form. Please try again or call us at 970-201-9619';
// let's do the sending
try
{
$emailText = "You have new message from your Website\n=============================\n";
foreach ($_POST as $key => $value) {
if (isset($fields[$key])) {
$emailText .= "$fields[$key]: $value\n";
}
}
mail($sendTo, $subject, $emailText, "From: " . $from);
$responseArray = array('type' => 'success', 'message' => $okMessage);
}
catch (\Exception $e)
{
$responseArray = array('type' => 'danger', 'message' => $errorMessage);
}
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$encoded = json_encode($responseArray);
header('Content-Type: application/json');
echo $encoded;
}
else {
echo $responseArray['message'];
}
請提供有關表格(字段名稱)的更多信息。 – Tom
「顯示用戶」如何? – McStuffins
主題行是否顯示用戶名?像主題將'拉胡爾的郵件'。 –