Q:

How to Attach Image into Mail Function Without HTML Form

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

A:

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);
?>

