Skip to content
Advertisement

add identifier to each page on site

So my website has multiple pages where I want people to have an option to send us a message. I already have setup a php mailer but all the mails have the same layout. How can I make to where if the message has been send form a specific page I add specific words to the mail? The mailsender works on both the pages but the layout and everything is the same.

THIS IS THE CODE THAT WORKS FOR ME:

<?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.nnNaam:n $name nnEmail:n $email_address nnTelefoon nummer:n $phone nnBericht:n$message nnURL:n $URL";
$headers = "From: no-reply@boonwijkkermis.comn"; // 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;
?>

Advertisement

Answer

This works for me

<?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.nnNaam:n $name nnEmail:n $email_address nnTelefoon nummer:n $phone nnBericht:n$message nnURL:n $URL";
$headers = "From: no-reply@boonwijkkermis.comn"; // 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;
?>
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement