PHP Mailto isn't sending variables

35 views Asked by At

I have trouble with sending emails on my website.

Here is a code:

$to  = '[email protected]' . ', ';
$to .= '[email protected]';
$subject = 'Potwierdzenie zakupu.';
$message = '$_POST[dostawa]';



$headers =
'MIME-Version: 1.0' . "\r\n" .
'Content-type: text/html; charset=utf-8' . "\r\n" .
'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

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

When I put text in my message it's sending text but if I put some variables it's sending $_POST[dostawa] I can print this variables before and after this code with echo.

2

There are 2 answers

2
Hassaan On

Change from

$message = '$_POST[dostawa]';

into

$message = $_POST['dostawa'];
1
Nishant Nair On

Since it is in single quote php consider it as string Recommend you to please put it into double quote

$message = "$_POST[dostawa]";