亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為網站上的每個頁面添加標識符

為網站上的每個頁面添加標識符

PHP
慕絲7291255 2022-06-17 10:26:26
所以我的網站有多個頁面,我希望人們可以選擇向我們發送消息。我已經設置了一個 php 郵件程序,但所有郵件的布局都相同。如果郵件是從特定頁面發送的,我如何在郵件中添加特定單詞?郵件發件人可以在兩個頁面上工作,但布局和一切都是一樣的。這是對我有用的代碼:<?php// Check for empty fieldsif(empty($_POST['name'])      ||   empty($_POST['email'])     ||   empty($_POST['phone'])     ||   empty($_POST['message'])   ||   !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))   {   echo "No arguments Provided!";   return false;   }$name = strip_tags(htmlspecialchars($_POST['name']));$email_address = strip_tags(htmlspecialchars($_POST['email']));$phone = strip_tags(htmlspecialchars($_POST['phone']));$message = strip_tags(htmlspecialchars($_POST['message']));$URL = $_SERVER['HTTP_REFERER'];// Create the email and send the message$to = '[email protected]'; // Add your email address inbetween the '' replacing [email protected] - This is where the form will send a message to.$email_subject = "Website Contact Form:  $name";$email_body = "Nieuwe mail ontvangen via boonwijkkermis.com.\n\nNaam:\n $name \n\nEmail:\n $email_address \n\nTelefoon nummer:\n $phone \n\nBericht:\n$message \n\nURL:\n $URL";$headers = "From: [email protected]\n"; // This is the email address the generated message will be from. We recommend using something like [email protected].$headers .= "Reply-To: $email_address";   mail($to,$email_subject,$email_body,$headers);return true;?>
查看完整描述

2 回答

?
胡說叔叔

TA貢獻1804條經驗 獲得超8個贊

您需要做的是在每個特定頁面中添加一個隱藏字段,以便能夠了解消息請求的來源,例如:


在一個頁面上:


<input type='hidden' name='from' value='page1'>

在另一頁上:


<input type='hidden' name='from' value='page2'>

然后在您的 php 文件中檢查該$_POST['from']值,以便能夠判斷請求來自哪個頁面。


所以你會做這樣的事情:


<?php

// Check for empty fields

if(empty($_POST['name'])      ||

   empty($_POST['email'])     ||

   empty($_POST['phone'])     ||

   empty($_POST['message'])   ||

   !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))

   {

   echo "No arguments Provided!";

   return false;

   }


$name = strip_tags(htmlspecialchars($_POST['name']));

$email_address = strip_tags(htmlspecialchars($_POST['email']));

$phone = strip_tags(htmlspecialchars($_POST['phone']));

$message = strip_tags(htmlspecialchars($_POST['message']));


if(!empty($_POST['from'])) { //if the from post var is not empty

    if($_POST['from'] == 'page1') { //if request came from page1

        $message .= " requested from page1"; //we append this text in the $message var

    }

}


// Create the email and send the message

$to = '[email protected]'; // Add your email address inbetween the '' replacing [email protected] - This is where the form will send a message to.

$email_subject = "Website Contact Form:  $name";

$email_body = "Nieuwe mail ontvangen via boonwijkkermis.com.\n\nNaam:\n $name \n\nEmail:\n $email_address \n\nTelefoon nummer:\n $phone \n\nBericht:\n$message";

$headers = "From: [email protected]\n"; // This is the email address the generated message will be from. We recommend using something like [email protected].

$headers .= "Reply-To: $email_address";   

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

return true;

?>

或者,如果您無法添加該隱藏字段,則可以$_SERVER['HTTP_REFERER']在 php 代碼中使用標頭,該標頭將包含請求來自的完整 URL。


查看完整回答
反對 回復 2022-06-17
?
茅侃侃

TA貢獻1842條經驗 獲得超22個贊

這對我有用


<?php

// Check for empty fields

if(empty($_POST['name'])      ||

   empty($_POST['email'])     ||

   empty($_POST['phone'])     ||

   empty($_POST['message'])   ||

   !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))

   {

   echo "No arguments Provided!";

   return false;

   }


$name = strip_tags(htmlspecialchars($_POST['name']));

$email_address = strip_tags(htmlspecialchars($_POST['email']));

$phone = strip_tags(htmlspecialchars($_POST['phone']));

$message = strip_tags(htmlspecialchars($_POST['message']));


$URL = $_SERVER['HTTP_REFERER'];





// Create the email and send the message

$to = '[email protected]'; // Add your email address inbetween the '' replacing [email protected] - This is where the form will send a message to.

$email_subject = "Website Contact Form:  $name";

$email_body = "Nieuwe mail ontvangen via boonwijkkermis.com.\n\nNaam:\n $name \n\nEmail:\n $email_address \n\nTelefoon nummer:\n $phone \n\nBericht:\n$message \n\nURL:\n $URL";

$headers = "From: [email protected]\n"; // This is the email address the generated message will be from. We recommend using something like [email protected].

$headers .= "Reply-To: $email_address";   

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

return true;

?>


查看完整回答
反對 回復 2022-06-17
  • 2 回答
  • 0 關注
  • 157 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號