Forum Moderators: coopster
I have a page that is built from a number of queries which I need to have the user email to the site owner in html format. I can pass the variable(s) that the page is made up from to the subject of the email e.g. $subject="Application for the position of $result[name]"; but I cannot get this or any other variable to display in the body of the message. I have tried everything I can think of and all I can get in the body is $result[name].
how are you trying to access the variables? Is this a post to the mailing script?
I assume you have looked at this?
mail() function [php.net]
have you tried just echo'ing what the value of the vars to see if it is a passing/assignment problem as opposed to a mail function problem?
$to .= "A Person <aperson@domain.com>";
$subject = "Application for the position of $result[name]";
$headers .= "From: $candidate[first]$candidate[last]<email@domain.com>\n";
$headers .= "X-Sender: <aperson@aperson.com>\n";
$headers .= "X-Mailer: PHP\n"; //mailer
$headers .= "X-Priority: 3\n"; //1 UrgentMessage, 3 Normal
$headers .= "Return-Path: <aperson@domain.com>\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
$message = '<head>
<style type="text/css">
.normalText { font-family: Tahoma, Verdana, Arial, sans-serif; font-size: 12px; font-weight: normal; color: #000000}
.smallText { font-family: Tahoma, Verdana, Arial, sans-serif; font-size: 10px; font-weight: normal; color: #000000}
body { margin-top: 0px; margin-bottom: 0px; background-color: #29166F}
.buttonText { font-family: Tahoma, Verdana, Arial, sans-serif; font-size: 10px; font-weight: normal; color: #FFFFFF; background-color: #29166F}
.bullets { font-family: CommonBullets; font-size: 14px; font-weight: bold; color: #D52C41}
hr { line-height: 3px; color: #29166F; width: 100%; height: 4px}
.lowercase
{text-transform: lowercase;}
</style>
</head>
<body>
<table width="750" border="0" cellspacing="0" cellpadding="5" bgcolor="#FFFFFF">
<tr><td valign="top" class="normalText"><div align="center">
<img src="http://www.domain.com/images/Logo.jpg" alt="Company Name" width="250" height="92"></div>
<br><div align="center">
Application for the position of <b>$result[name]</b> in $resultjob[city], $result[countryname]<br>
by <b>$candidate[salutation] $candidate[first] $candidate[last]
</b><br><br></div>
and more html until closing tags
';
mail($to, $subject, $message, $headers);
I get a prfectly formatted email with everything as I want it in the to and subject areas but in the body of the email I get $candidate[first] instead of its value.
$message = '<head>
--your html--
';
with
$message = <<<END
<head>
--your html--
END;
and everything will work ok.
my guess is this, but I am searching for supporting docs, if you use single quotes in your var assignment it won't resolve the vars.
Thatīs what Single quoted strings are not subject to variable interpolation is about. The php docs call it Variable parsing [php.net].
Andreas
yep, but I had the reply window open and didn't see your post ;)
I found another good one
[zend.com...]
<added>Is it just me or is the site search on php.net getting worse and worse. It seems to find nothing except specific functions when I use the search.
PS I agree about the search, I've been looking for most of the afternoon and evening.
Thanks andreasfriedrich, normally I would try to do that, and probably will once I have got it to work. All semms to be going according to plan now.