Skip to content Skip to sidebar Skip to footer

How To Send Image In Php Mail Function

I want to send image in mail.How to add image so that it will show in the email I want to add image to the CLIENT MESSAGE BODY. How to use html in client message body? Here is my c

Solution 1:

You cannot display images on text/plain emails as shown above. You must send it as text/html.

So you first have to extend your headers like this:

$header="From: $noreply@intaxfin.com\nMIME-Version: 1.0\nContent-Type: text/html; charset=utf-8\n";

Then you must update your mailcontent replacing \n or linebreaks with html tags <br> or even <p>

Then you also can include image tags having the image you want to show in the email

<imgsrc="http://www.yourserver.com/myimages/image1.jpg">

This will be downloaded from your webserver when recipient opens it.

.

BUT the much better way will be to use phpMailer Class

Using this, you will be able to include any images IN your email, without need to download it from any website. It is easy to learn and absolutely customizable.

By the way: You should use quotation marks for your $body and $body2 values...

$body= "<<<EOD
Contact Form Details of $nameFeild

Name: $nameFeild \n
City: $cityFeild \n
Country: $countryFeild \n"

Solution 2:

$headers= 'MIME-Version: 1.0' . "\r\n";
$headers.= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$message="<html><head>
<title>Your email at the time</title>
</head>
<body>
<img src=\"http://www.myserver.com/images_folder/my_image.jpg\">
</body>"
mail($email_to, $email_subject , $message,$headers);

Post a Comment for "How To Send Image In Php Mail Function"