小编典典

通过PHP在电子邮件中发送HTML

html

如何使用PHP发送带有图片的HTML格式的电子邮件?

我想要一个带有一些设置和HTML输出的页面,该页面通过电子邮件发送到一个地址。我该怎么办?

主要问题是附加文件。我怎样才能做到这一点?


阅读 349

收藏
2020-05-10

共1个答案

小编典典

非常简单,将图像保留在服务器上,然后将PHP + CSS发送给它们…

$to = 'bob@example.com';

$subject = 'Website Change Reqest';

$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: susan@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";

$message = '<p><strong>This is strong text</strong> while this is not.</p>';


mail($to, $subject, $message, $headers);

正是这一行告诉邮件发件人和收件人,该电子邮件包含(希望)格式正确的HTML,需要对其进行解释:

$headers .= "Content-Type: text/html; charset=UTF-8\r\n";

这是我获得信息的链接。(link …)

您将需要安全…

2020-05-10