尝试使用PHP在电子邮件主题行中显示两个连接变量

I am trying to display two concatenated variables in a subject line through an mailer.php page, but the subject line in the email always comes in blank. Below is the pertinent code.

/* Subject and To */

$to = 'nnorman@dimplexthermal.com';
$subject = $company . ' ' . $name;

/* Gathering Data Variables */

$name = $_POST['name'];
$email = $_POST['email'];
$company = $_POST['company'];

$body = <<<EOD
<br><hr><br>
Email: $email <br>
Name: $name <br>
Company: $company <br>

EOD;

$headers = "From: $email
";
$headers .= "Content-type: text/html
";
$success = mail($to, $subject, $body, $headers);
$to = 'nnorman@dimplexthermal.com';
$subject = $company . ' ' . $name;

/* Gathering Data Variables */

$name = $_POST['name'];
$email = $_POST['email'];
$company = $_POST['company'];

You're not setting $company and $name until after you use them in $subject

Try switching the lines round:

/* Gathering Data Variables */

$name = $_POST['name'];
$email = $_POST['email'];
$company = $_POST['company'];

$to = 'nnorman@dimplexthermal.com';
$subject = $company . ' ' . $name;