如何使用 PHP 发送带有图片的 HTML 格式的电子邮件?
我想要一个包含一些设置和 HTML 输出的页面,通过电子邮件发送到一个地址。我该怎么办?
主要问题是附加文件。我该怎么做?
最佳答案
这很简单。将图像留在服务器上,然后将 PHP + CSS 发送给它们...
$to = 'bob@example.com';
$subject = 'Website Change Request';
$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)
不过,你需要安全……
关于php - 通过 PHP 在电子邮件中发送 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11238953/