Php html email img to

You're trying to send an email with an HTML body that includes an image using PHP!

Here's a basic example of how you can do this:

<?php
// Set the email headers
$headers = 'MIME-Version: 1.0'. "\r\n";
$headers.= 'Content-type: text/html; charset=UTF-8'. "\r\n";

// Set the email body
$body = '<html><body>';
$body.= '<img src="cid:image1" alt="Image">';
$body.= '</body></html>';

// Set the image file
$image = 'path/to/image.jpg';

// Set the email subject and recipient
$subject = 'Test Email with Image';
$to = '[email protected]';

// Send the email
mail($to, $subject, $body, $headers);

// Add the image to the email
$fp = fopen($image, 'rb');
$data = fread($fp, filesize($image));
fclose($fp);

// Set the image headers
$headers.= 'Content-Disposition: inline; filename="'. $image. '"'. "\r\n";
$headers.= 'Content-Type: image/jpeg'. "\r\n";

// Send the image
mail($to, $subject, $data, $headers);
?>

In this example, we're using the mail() function to send the email. We're setting the email headers to include the MIME-Version and Content-type headers, which tell the email client that the email body is in HTML format.

We're also setting the email body to include an <img> tag that references the image using the cid attribute. This tells the email client to look for the image in the email headers.

We're then setting the image file and sending it as a separate email using the mail() function again. We're setting the Content-Disposition header to inline, which tells the email client to display the image inline with the email body. We're also setting the Content-Type header to image/jpeg, which tells the email client that the image is a JPEG file.

Note that this is just a basic example, and you may need to modify it to fit your specific use case. Additionally, be aware that sending large images or multiple images in a single email can be problematic, and you may want to consider using a more robust email library or service to handle this.