2

I have a very simple code like this

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

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

can you please let me know how I can attach an image to that? For example let say I have an image in img folder called test.png

Thanks

Behseini
  • 6,066
  • 23
  • 78
  • 125

2 Answers2

2

use the PHPmailer script, is the better way, wp_mail is even more easy but that´s another subject, here is a post that will solve your problem.

Send attachments with PHP Mail()?

using wp_mail would be something as easy as this:

<?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);
?>
Community
  • 1
  • 1
-1

You'll have to request the image through http

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