Reputation: 129
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 = '[email protected]';
$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);
Upvotes: 1
Views: 697
Reputation: 10732
$to = '[email protected]';
$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 = '[email protected]';
$subject = $company . ' ' . $name;
Upvotes: 4