第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

為網(wǎng)站上的每個頁面添加標(biāo)識符

為網(wǎng)站上的每個頁面添加標(biāo)識符

PHP
慕絲7291255 2022-06-17 10:26:26
所以我的網(wǎng)站有多個頁面,我希望人們可以選擇向我們發(fā)送消息。我已經(jīng)設(shè)置了一個 php 郵件程序,但所有郵件的布局都相同。如果郵件是從特定頁面發(fā)送的,我如何在郵件中添加特定單詞?郵件發(fā)件人可以在兩個頁面上工作,但布局和一切都是一樣的。這是對我有用的代碼:<?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 = 'boonwijkkermis@gmail.com'; // Add your email address inbetween the '' replacing yourname@yourdomain.com - 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: no-reply@boonwijkkermis.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com.$headers .= "Reply-To: $email_address";   mail($to,$email_subject,$email_body,$headers);return true;?>
查看完整描述

2 回答

?
胡說叔叔

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超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 = 'boonwijkkermis@gmail.com'; // Add your email address inbetween the '' replacing yourname@yourdomain.com - 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: no-reply@boonwijkkermis.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com.

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

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

return true;

?>

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


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

TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超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 = 'boonwijkkermis@gmail.com'; // Add your email address inbetween the '' replacing yourname@yourdomain.com - 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: no-reply@boonwijkkermis.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com.

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

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

return true;

?>


查看完整回答
反對 回復(fù) 2022-06-17
  • 2 回答
  • 0 關(guān)注
  • 156 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號