JustStatic
JustStatic

Reputation: 25

How to add text to email sent from a php contact form

Hi all this is the PHP im using:

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n Message: $message";
$recipient = "[email protected]";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='contact.html' style='text-decoration:none;
color:#ff0099;'> Return Home</a>";
?>

Its working perfectly fine but i would like there to be some text sent with this email that says "This is from your website" or something similar to tell the recipient that it isnt spam (my client isn't tech friendly and sees everything plain text as spam). I'm very new to PHP with nearly 0 knowledge and have no idea how to add something like that. I did have a go at making a new variable with the string inside and then include that in the:

mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");

line but with no success. Thanks for taking the time any help would be welcome.

Upvotes: 1

Views: 1103

Answers (3)

Rich701
Rich701

Reputation: 311

$formcontent='This is from your website\n From: ' . $name . '\n Phone: ' . $phone . '\n Message: ' . $message;

Upvotes: 0

Teena Thomas
Teena Thomas

Reputation: 5239

You can either add it in the $subject or $message.

  $subject = "Contact Form: This is from your website"; // OR
  $message .= "This is from your website";

Upvotes: 0

Tim Withers
Tim Withers

Reputation: 12059

Change this line: $formcontent=" From: $name \n Phone: $phone \n Message: $message";

Add the content you want:

$formcontent="This is from your website\n From: $name \n Phone: $phone \n Message: $message";

Or if you want to change the subject, this line: $subject = "Contact Form";

Add the content you want:

$subject = "Contact Form - From your website";

Upvotes: 3

Related Questions