1

i am totally lost with why i am getting this error at this code:

$finalmessage = "
From:$_POST['name']
Email:$_POST['email']
Message:$_POST['message']
";

Here is the entire mail php code below:

<?php

$name = $_POST['name'];
$surname = $_POST['surname'];
$email = $_POST['email'];
$message = $_POST['message'];
$support_address = "info@bkslegal";
$headers = "From: ".$email;
$header2 = "From: ".$support_address;
$finalmessage = "
From:$_POST['name']
Email:$_POST['email']
Message:$_POST['message']
";

if ( $name == "")

{   
}
else
{
mail("$support_address","finalmessage",$headers);
$result = "Your message has been sent succesfully!" 

mail("$email","Thank you for contacting us!","We will soon be in contact with you!",$header2);  
}
?>
  • Possible duplicate of [Reference - What does this error mean in PHP?](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – ChristianF Nov 24 '16 at 10:14
  • This error is most often encountered when attempting to reference an array value with a quoted key for interpolation inside a double-quoted string, when the entire complex variable construct is not enclosed in {}. http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php/13935532#13935532 – phobia82 Nov 24 '16 at 10:23

1 Answers1

0

I see that you wrote your parameters wrong. You wrote:

mail("$support_address","finalmessage",$headers);

It should be:

mail ($support_address, $subject, $message, $headers);

and remove this line

//mail("$email","Thank you for contacting us!","We will soon be in contact with you!",$header2);

PHP mail SYNTAX is:

mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

Final code :

<?php
$name = $_POST['name'];
$surname = $_POST['surname'];
$email = $_POST['email'];
$support_address = "info@bkslegal";

if($name == "") {
   //show somting error message
}
else
{
    $Message = "From:".$name."<br />";
    $Message .= "Email:".$email."<br />";
    $Message .= "Message:". $_POST['message'];

    $to = $support_address;
    $subject = "new message";

    // To send HTML mail, the Content-type header must be set
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    // Additional headers
    $headers .= 'To: Name <$to>' . "\r\n";
    $headers .= 'From:  $name <$email>' . "\r\n";
    $headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
    $headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";


    if(mail($to, $subject, $Message, $headers)) {
       echo "Your message has been  Sent";
    } else {
       echo "Mesage Error";
    }  
}
?>

Note : Use any mail library for prevent vulnerable to header injection like PHPMailer

Razib Al Mamun
  • 2,663
  • 1
  • 16
  • 24