开发者

HTML style email in php

I can't figure out what I'm missing.

$info = mysql_fetch_array($dataz);

$body = '
<html>
<head>
  <title> Summary Report </title>
</head>
<body>
  <p>Type of incident: {$info['type']}</p>
  <p>Date upon entry: {$info['date']}</p>   
  <p>Time upon entry: {$info['time']}</p>
  <p>Your account name: {$info['reporter']}</p>
  <p>Your incident ID number: {$info['ID']}</p>
  <p>Your description of the incident: {$info['desc']}</p>  
</body>
</html>';

$headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";


mail(开发者_高级运维$info['email'], "subject!", $body, $headers);


You're initialising your $body string with single quotes when you need to use double quotes to take advantage of PHP's variable replacement.


You can't use variables in single-quotes.

php > $hallo = 'Bla';
php > $hello = 'Bla';
php > echo '{$hello} there.';
{$hello} there.
php > echo "{$hello} there.";
Bla there.

Use double quotes (") in your $body instead :)


Your variables should be added in to your email in the following way:

$info = mysql_fetch_array($dataz);

$body = '
<html>
<head>
  <title> Summary Report </title>
</head>
<body>
  <p>Type of incident: ' . $info['type'] . '</p>
  <p>Date upon entry: ' . $info['date'] . '</p>   
  <p>Time upon entry: ' . $info['time'] . '</p>
  <p>Your account name: ' . $info['reporter'] . '</p>
  <p>Your incident ID number: ' . $info['ID'] . '</p>
  <p>Your description of the incident: ' . $info['desc'] . '</p>  
</body>
</html>';

$headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";


mail($info['email'], "subject!", $body, $headers);

Presumably that's one of your problems gone

Is the message actually sending? Is it that it's not showing in the HTML format, as expected?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜