0

I am using this simple php mail function and I would like to add to message another text like "this message is from website".

$email="kontakt@fotografernevesterbro.dk";
$from=$_POST["email"];
$subject=$_POST["subject"];
$message=$_POST["message"] + $sitemessage;
$sitemessage= "this is message from website";

mail ($email, $subject, $message, "From:".$from);

I tried to add another variable and put it into mail function but it doesn't work.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Possible duplicate of [How to send an email using PHP?](http://stackoverflow.com/questions/5335273/how-to-send-an-email-using-php) – jogo Dec 01 '15 at 09:10

2 Answers2

2

Use . to concatenate (not +) and $sitemessage should be appended to $message after it has been assigned a value.

$email="kontakt@fotografernevesterbro.dk";
$from=$_POST["email"];
$subject=$_POST["subject"];
$sitemessage= "this is message from website";
$message=$_POST["message"] . $sitemessage;

mail ($email, $subject, $message, "From:".$from);
Thamilhan
  • 13,040
  • 5
  • 37
  • 59
-1

This code will simply do what you want.

  $email="kontakt@fotografernevesterbro.dk";
    $from=$_POST["email"];
    $subject=$_POST["subject"];
    $headers = "From: $from  ";
    $message=$_POST["message"];
    $message .= " this is message from website";

    mail ($email, $subject, $message, $headers);
Terabyte
  • 455
  • 2
  • 12
  • *I have modified the code and tested.* - no you haven't. See [this](http://stackoverflow.com/questions/34016443/adding-message-to-php-mail-funcion#comment55792833_34016640) – ʰᵈˑ Dec 01 '15 at 13:59