Php 如何在没有HTML表单的情况下将图像附加到邮件函数中

Php 如何在没有HTML表单的情况下将图像附加到邮件函数中,php,Php,我有这样一个非常简单的代码 <?php $to = "somobe@yahoo.ca"; $subject = "I am sending an image"; $txt = "Get the Image"; $headers = "From: someone else"; mail($to,$subject,$txt,$headers); ?> 你能告诉我怎样才能在上面贴上图片吗?例如,假设我在img文件夹中有一个名为test.png 谢谢您必须通过http请求图像 <

我有这样一个非常简单的代码

<?php
$to = "somobe@yahoo.ca";
$subject = "I am sending an image";
$txt = "Get the Image";
$headers = "From: someone else";

mail($to,$subject,$txt,$headers);
?>

你能告诉我怎样才能在上面贴上图片吗?例如,假设我在
img
文件夹中有一个名为
test.png


谢谢

您必须通过http请求图像

<img src="http://www.yourdomain.com/img/test.png">

使用PHPmailer脚本是更好的方法,wp\u邮件更简单,但这是另一个主题,这里有一篇文章可以解决您的问题

使用wp_邮件将非常简单:

<?php
$to = "somobe@yahoo.ca";
$subject = "I am sending an image";
$txt = "Body of the message (can be a html or text/plain)";
$headers = "From: someone else";
$attachment= "image.jpg";// just like this in the root folder of your script, if you have your image in another folder then just write the path.
wp_mail($to,$subject,$txt,$headers,$attachment);
?>