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

尝试使用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);

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

  / * Subject and To * / 
 
 $ to ='nnorman@dimplexthermal.com'; 
 $ subject = $ company。  ''。  $ name; 
 
 / *收集数据变量* / 
 
 $ name = $ _POST ['name']; 
 $ email = $ _POST ['email']; 
 $ company = $ _POST [  'company']; 
 
 $ body =&lt;&lt;&lt;&lt; EOD 
&lt; br&gt;&lt; hr&gt;&lt; br&gt; 
电子邮件:$ email&lt; br&gt; 
名称:$ name&lt; br&gt;  
公司:$ company&lt; br&gt; 
 
EOD; 
 
 $ headers =“From:$ email 
 
”; 
 $ headers。=“Content-type:text / html 
 
  “; 
 $ success = mail($ to,$ subject,$ body,$ headers); 
  code>  pre> 
  div>

$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;