私はそれを持っているようにしようとしています。ユーザーがフォームを送信するときに、「[Name of user]からのお問い合わせ」のようなユーザーの名前が表示されます。どのようにセットアップされているのかは、「サイトからの連絡フォーム」という件名で私に届きます。どのようにコードを修正してそのようにすることができますか?連絡先フォームの名前文字列
<?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
件名にユーザーの名前が表示されますか?同じような主題は 'Rahulからのメール'です。 –