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

时间:2012-08-21 20:24:42

标签: php forms

我试图通过mailer.php页面在主题行中显示两个连接变量,但电子邮件中的主题行总是空白。以下是相关代码。

/* 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\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($to, $subject, $body, $headers);

1 个答案:

答案 0 :(得分:4)

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

/* Gathering Data Variables */

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

您在$company

中使用$name$subject之后才开始设置/* Gathering Data Variables */ $name = $_POST['name']; $email = $_POST['email']; $company = $_POST['company']; $to = 'nnorman@dimplexthermal.com'; $subject = $company . ' ' . $name; 和{{1}}

尝试切换线条:

{{1}}