/    Sign up×
Community /Pin to ProfileBookmark

how to send img tag and view image in mail

i have send mail with img tag. i m can not view the image only in mail some time show img or blank image.

how to solve this my code is blow

[code=php]
$to = ‘[email protected]’;
$from = ‘[email protected]’;
$repto = ‘[email protected]’;

$subject = ‘Website Change Reqest’;

$headers = “From: ” . $from . “rn”;
$headers .= “Reply-To: “. $repto. “rn”;
$headers .= “CC: $torn”;
$headers .= “MIME-Version: 1.0rn”;
$headers .= “Content-Type: text/html; charset=ISO-8859-1rn”;

$message = ‘<html><body>’;
$message .= ‘<h1>Hello, World!</h1>’;
$message .= ‘</body></html>’;
$message = ‘<img src=”rose.jpg” alt=”img”>’;

$mail_sent = @mail( $to, $subject, $message, $headers );[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@HHCOwnerJul 16.2009 — I found 5 different problems with your code!

[B]~ First ~[/B]

In your code, you forgot to add a third period before the equal sign on $message, so lets start with that ...

[code=html]
$message = '<html><body>';
$message .= '<h1>Hello, World!</h1>';
$message .= '</body></html>';
$message .= '<img src="rose.jpg" alt="img">';
[/code]


[B]~ Second ~[/B]

Your $message variables were a little out of order, try it like this ...

[code=html]
$message = '<html><body>';
$message .= '<h1>Hello, World!</h1>';

$message .= '<img src="rose.jpg" alt="img">';
$message .= '</body></html>';
[/code]


[B]~ Third ~[/B]

You need to switch the single quotations with double quotations and vise versa ...

[code=html]
$message = "<img src='rose.jpg' alt='img'>";
[/code]


[B]~ Fourth ~[/B]

For the src in your image, you need to put your entire url rather than just "rose.jpg" like so ...

[code=html]
$message .= "<img src='http://yourwebsite.com/rose.jpg' alt='img'>";
[/code]


[B]~ Fifth ~[/B]

You need to add a / at the end of your image html like so ...

[code=html]
$message .= "<img src='http://yourwebsite.com/rose.jpg' alt='img' />";
[/code]


[B]~ and Finally ~[/B]

You can shorten it a little by removing the <html> tags. They aren't required for the script to run ...

[code=html]
$message = "<body>";
$message .= "<h1>Hello, World!</h1>";
$message .= "<img src='http://yourwebsite.com/rose.jpg' alt='img' />";
$message .= "</body>";
[/code]


Next time check every minor detail. ?

Hope this helps. ?
×

Success!

Help @jsaravananj spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.9,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...