如何使用 PHP 发送带有图片的 HTML 格式的电子邮件?
我想要一个包含一些设置和 HTML 输出的页面,该页面通过电子邮件发送到一个地址。我应该怎么办?
主要问题是附加文件。我怎样才能做到这一点?
原文由 Abadis 发布,翻译遵循 CC BY-SA 4.0 许可协议
您需要使用图像的绝对路径对 HTML 内容进行编码。通过 绝对 路径,我的意思是您必须将图像上传到服务器,并且在图像的 src
属性中,您必须提供直接路径,就像这样 <img src="http://yourdomain.com/images/example.jpg">
。
以下是供您参考的 PHP 代码:取自 _邮件_:
<?php
// Multiple recipients
$to = 'aidan@example.com' . ', '; // Note the comma
$to .= 'wez@example.com';
// Subject
$subject = 'Birthday Reminders for August';
// Message
$message = '
<p>Here are the birthdays upcoming in August!</p>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
原文由 Subhajit 发布,翻译遵循 CC BY-SA 4.0 许可协议
2 回答1.5k 阅读✓ 已解决
2 回答1.5k 阅读✓ 已解决
1 回答1.3k 阅读✓ 已解决
2 回答922 阅读✓ 已解决
1 回答929 阅读✓ 已解决
2 回答920 阅读✓ 已解决
1 回答1.2k 阅读✓ 已解决
这很简单。将图像留在服务器上并将 PHP + CSS 发送给它们……
正是这一行告诉寄件人和收件人电子邮件包含(希望)格式良好的 HTML,它需要解释:
这是我从中获得信息的链接…( 链接)
不过你需要安全……