Reputation: 26732
My three concerns, tried different combos with no result, googled but little or no help --
[email protected]
to the email id to see the result.My Working Code -->
<?php
header('Content-type: image/jpeg');
$jpg_image = imagecreatefromjpeg('http://dummyimage.com/600x400/f5f5f5/fff.jpg');
$black = imagecolorallocate($jpg_image, 1, 1, 1);
$font_path = 'myfont/arial.ttf';
$text = "Swapnesh Sinha!";
imagettftext($jpg_image, 24, 0, 175, 85, $black, $font_path, $text);
$tip = imagejpeg($jpg_image);
$imageData = base64_encode($tip);
//$src = 'data: '.mime_content_type($jpg_image).';base64,'.$imageData;
imagedestroy($jpg_image);
?>
<html>
<head></head>
<body>
<p>
<?php
$to = '[email protected]';
$subject = "Thisa is a email test to find image work";
$message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MY SITE TITLE</title>
</head><body><table><tr><td>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</td></tr><tr><img src="'.'http://mysiteurl/addtext.php'.'" /></tr></table></body></html>';
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$bool = mail($to, $subject, $message, $headers);
if($bool)
echo "Email Sent";
else
echo "Email Not Sent";
?>
</body>
</html>
NOTE - In <img src="'.'http://mysiteurl/addtext.php'.'" />
http://mysiteurl/addtext.php
is the same where we have all this above content.
Upvotes: 3
Views: 2875
Reputation: 10781
First thing I'd do is check your apache/IIS logs to ensure that the URL isn't being called twice (just a sanity check).
If the PHP page you've added to your OP is http://mysiteurl/addtext.php
, then it would be called twice, once renderering the HTML, then the browser would call it again when rendering the <img ...>
tag.
To fix this you need to either split it into two PHP files (recommended), or pass a GET parameter to toggle the image processing.
You'll also need to add $headers .= "Content-type: text/html\r\n";
so that the email is rendered as html and not plain text.
Upvotes: 2