PHP HTML电子邮件带有标签发送

问题描述 投票:1回答:1
$to = '[email protected]';
$subject = 'Coupon Claimed!';
$header  = 'From: [email protected]';
$claimed = '<html><body>';
$claimed .= '<h1>Hello, World!</h1>';
$claimed .= '</body></html>';


mail($to, $subject, $claimed, $header);

我有这个简单的html php电子邮件,但是当它发送时,包括标签在内的所有内容都会被包含在内。

1

谷歌教程显示了类似的示例,例如我所做的代码,想知道我如何只能发送div内容。

php html email html-email
1个回答
2
投票

您需要像这样将Content-type添加到标题中:

$to = '[email protected]';
$subject = 'Coupon Claimed!';
$claimed = '<html><body>';
$claimed .= '<h1>Hello, World!</h1>';
$claimed .= '</body></html>';
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= 'From: [email protected]\r\n';

mail($to, $subject, $claimed, $headers);
© www.soinside.com 2019 - 2024. All rights reserved.