A1Nasir A1Nasir - 1 month ago 16
PHP Question

Add Picture In Email Body

i am not too good with PHP and programming but still i am trying to learn it in every possible way. I need help from experts. My code to send email is as below. i am able to send email, but the problem is, picture is not displaying in email body and it's showing a cross sign. any possible idea and suggestion is appreciated.

<?php

function send_email($from, $to, $subject, $message){
$headers = "From: ".$from."\r\n";

$headers .= "Return-Path: ".$from."\r\n";
$headers .= "CC: abc@gmail.com\r\n , xyz@gmail.com\r\n";
$headers .= "BCC: \r\n";
//set content type to HTML
$headers .= "Content-type: text/html\r\n";

if ( mail($to,$subject,$message,$headers) )
{

header("location:contact-us.php?msg=msgsent");

}
else
{
header("location:contact-us.php?msg=notsent");
}

}
//Function ends here
$from_email="";
$to_email="LMN@gmail.com";
$message.="<html><body background='images/bg11.jpg'>";
$message.="<p style=' color: #006789;'>Dear Team,</p> ";
$message.= "<p style=' color: #006789;'>You have received a feedback from $name & below are the details!!! </p>";
$message.= "<img src=images/c22.jpg>";
$message.="</body></html> ";
send_email(from_email,$to_email,$subject,$message);
?>

Answer

You are using a relative path:

<img src=images/c22.jpg>

When you open your mail, that path will mean nothing in a mail client and it is highly unlikely to exist on a webmail client. And if it does, it is not your image...

If you have that image stored on a web-server, you should use the absolute path to that image:

<img src="http://www.your-server.com/images/c22.jpg">