के साथ एक इनलाइन संलग्न छवि के साथ एक HTML ईमेल कैसे भेजें, मेरे पास एक PHP स्क्रिप्ट है जो एक संलग्न छवि के साथ एक HTML ईमेल भेजती है। यह बेहद काम करता है, हालांकि, मुझे ईमेल निकाय में <img>
टैग में प्रदर्शित करने के लिए अनुलग्नक नहीं मिल सकता है। संलग्न फ़ाइल को postcard.png
कहा जाता है और सर्वर पर मूल फ़ाइल नाम 4e60348f83f2f.png
है। मैंने छवि यूआरएल को विभिन्न चीजों के रूप में देने की कोशिश की है: cid:postcard.png
, cid:4e60348f83f2f.png
, postcard.png
, और 4e60348f83f2f.png
। कुछ भी काम नहीं करता है।PHP
मुझे लगता है कि महत्वपूर्ण हिस्सा है कि मैं गलत कर रहा हूँ यहाँ है, यह एक इनलाइन लगाव के बजाय एक अलग लगाव है कि मैं उपयोग कर सकते हैं बनाता है क्योंकि:
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="$fname" // i.e.: "postcard.png"
मैं कोशिश की है इसे बदलने का उपयोग करने के एक सीआईडी लेकिन मैं वास्तव में ऐसा करने के लिए कैसे पता नहीं है, और इस फ्लॉप 'काम पर सब:
Content-Transfer-Encoding: base64
Content-ID: <$fname> // i.e.: postcard.png
यहाँ पूर्ण कोड है: (यह php mail()
पेज में एक टिप्पणी से this code पर आधारित है।)
<?php
$to = "[email protected]";
$email = "[email protected]";
$name = "Namename";
$subject = "An inline image!";
$comment = "Llookout <b>Llary</b> it's <br> the <b>Ll</b>andllord!<br><img src='cid:postcard.png'><br><img src='cid:4e60348f83f2f.png'><img src='postcard.png'><br><img src='4e60348f83f2f.png'>";
$To = strip_tags($to);
$TextMessage =strip_tags(nl2br($comment),"<br>");
$HTMLMessage =nl2br($comment);
$FromName =strip_tags($name);
$FromEmail =strip_tags($email);
$Subject =strip_tags($subject);
$boundary1 =rand(0,9)."-"
.rand(10000000000,9999999999)."-"
.rand(10000000000,9999999999)."=:"
.rand(10000,99999);
$boundary2 =rand(0,9)."-".rand(10000000000,9999999999)."-"
.rand(10000000000,9999999999)."=:"
.rand(10000,99999);
$filename1 = "4e60348f83f2f.png"; //name of file on server with script
$handle =fopen($filename1, 'rb');
$f_contents =fread($handle, filesize($filename1));
$attachment=chunk_split(base64_encode($f_contents));
fclose($handle);
$ftype ="image/png";
$fname ="postcard.png"; //what the file will be named
$attachments='';
$Headers =<<<AKAM
From: $FromName <$FromEmail>
Reply-To: $FromEmail
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="$boundary1"
AKAM;
$attachments.=<<<ATTA
--$boundary1
Content-Type: $ftype;
name="$fname"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="$fname"
$attachment
ATTA;
$Body =<<<AKAM
This is a multi-part message in MIME format.
--$boundary1
Content-Type: multipart/alternative;
boundary="$boundary2"
--$boundary2
Content-Type: text/plain;
charset="windows-1256"
Content-Transfer-Encoding: quoted-printable
$TextMessage
--$boundary2
Content-Type: text/html;
charset="windows-1256"
Content-Transfer-Encoding: quoted-printable
$HTMLMessage
--$boundary2--
$attachments
--$boundary1--
AKAM;
// Send email
$ok=mail($To, $Subject, $Body, $Headers);
echo $ok?"<h1> Mail sent!</h1>":"<h1> Mail not sent!</h1>";
?>
[PHPMailer] (http://phpmailer.worxware.com) या [स्विफ्टमेलर] (http://swiftmailer.org) का उपयोग करें। दोनों स्क्रैच से एमआईएमई संदेश बनाने के लिए आप जो भी कर रहे हैं उसके विपरीत, बिल्कुल बिना किसी दर्द के इन-लाइन अनुलग्नकों को अनुमति दें। –
ऐसा नहीं है कि इसे हाथ से करना संभव नहीं है, लेकिन स्विफ्टमेलर या PHPMailer का उपयोग करना कम बोझिल होगा। - संभावित डुप्लिकेट [PHPMailer के साथ ईमेल भेजें - शरीर में एम्बेड छवि] (http://stackoverflow.com/questions/3708153/send-email-with-phpmailer-embed-image-in-body) – mario
@Marc B: मुझे पता नहीं, मैंने PHPMailer के साथ एक बार एक हैंगनेल टाइपिंग खींचा, यह कुछ हद तक दर्दनाक था। –