It is necessary to send a message with the image: Display the illustration in the letter and hang the html map on it.

Function to send:

function SendMyMail($to,$from,$subject,$message,$boundary,$filename){ $headers = "From: $from\nReply-To: $from\n"; $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\""; $body = "--" . $boundary . "\n"; $body .= "Content-type: text/html; charset='utf-8'\n"; $body .= "Content-Transfer-Encoding: quoted-printablenn"; $body .= "Content-Disposition: attachment; filename==?utf-8?B?".base64_encode($filename)."?=\n\n"; $body .= $message."\n"; $body .= "--$boundary\n"; $file = fopen($filename, "r"); //ΠžΡ‚ΠΊΡ€Ρ‹Π²Π°Π΅ΠΌ Ρ„Π°ΠΉΠ» $text = fread($file, filesize($filename)); //Π‘Ρ‡ΠΈΡ‚Ρ‹Π²Π°Π΅ΠΌ вСсь Ρ„Π°ΠΉΠ» fclose($file); //Π—Π°ΠΊΡ€Ρ‹Π²Π°Π΅ΠΌ Ρ„Π°ΠΉΠ» $body .= "Content-Type: application/octet-stream; name==?utf-8?B?".base64_encode($filename)."?=\n"; $body .= "Content-Transfer-Encoding: base64\n"; $body .= "Content-Disposition: attachment; filename==?utf-8?B?".base64_encode($filename)."?=\n\n"; $body .= chunk_split(base64_encode($text))."\n"; $body .= "--".$boundary ."--\n"; mail($to, $subject, $body, $headers); //ΠžΡ‚ΠΏΡ€Π°Π²Π»ΡΠ΅ΠΌ письмо } 

html letters:

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content="text/html; charset=UTF-8" http-equiv=Content-Type> <MAP name=FPMap0> <AREA href="site.com/" shape="rect" coords="112, 73, 668, 132"> </MAP> <BODY> <P align=center> <IMG border=0 src="сюда Π½Π°Π΄ΠΎ Π²ΡΡ‚Π°Π²ΠΈΡ‚ΡŒ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ" width=800 height=1964 useMap=#FPMap0> </P> </BODY> </HTML> 

How can I refer to the image in img ?

I tried to simply substitute the path to the picture on the Internet, but Outlook does not display it.

    4 answers 4

    In your php-code, you attach the picture as an attachment, which in principle comes to nothing. Distributors of all sorts of advertising bulletins, etc. form the html-code of the letter, in such a way that all the pictures are pulled from their servers - you have to look in this direction. In turn, most email clients do not load pictures by default for security purposes, unlike most web interfaces (a'lya mail.ru , yandex.ru , ...).

    • >> How do I coexist in the IMG picture ??? I tried to substitute just the path to the picture in nete, but Autluk does not display it ... Yeah, I already understood that, but the fact is that right now the mailing is done with scribed pictures and they are displayed) so I wonder how to do it? - KARTOH
    • you need to insert another Content-ID item: $ id into your head and when you want to display a picture in the address, enter "cid: $ id" - KARTOH

    this helped me.

     // ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ $attach = array( 'http://vk-book.ru/img/scroll_mouse.jpg', 'http://vk-book.ru/img/ugly.png' ); // Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ°Π»Π°ΡΡŒ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° ΠΈ Π΅Π΅ Π½Π΅ Π±Ρ‹Π»ΠΎ Π² Π°Ρ‚Ρ‚Π°Ρ‡Π΅ // ΠΏΡƒΡ‚ΡŒ ΠΊ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ΅ задаСтся Ρ‡Π΅Ρ€Π΅Π· CID: - Content-ID // тСстовый тСкст $text = ' <div style="width: 700px; margin: 0 auto;"> <h1>Ρ‚Π΅Π»ΠΎ письма с ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΎΠΉ</h1> <h2>Π‘Π»ΠΎΠΊ ΠΏΠΎ Ρ†Π΅Π½Ρ‚Ρ€Ρƒ</h2> <p> <img style="float: left; margin-right: 15px; margin-bottom: 15px;" src="cid:scroll_mouse.jpg" width="128" height="128" /> Какой-Ρ‚ΠΎ тСкст Π²ΠΎΠΊΡ€ΡƒΠ³ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ. Какой-Ρ‚ΠΎ тСкст Π²ΠΎΠΊΡ€ΡƒΠ³ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ. Какой-Ρ‚ΠΎ тСкст Π²ΠΎΠΊΡ€ΡƒΠ³ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ. Какой-Ρ‚ΠΎ тСкст Π²ΠΎΠΊΡ€ΡƒΠ³ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ. <br/> <img style="float: left; margin-right: 15px; margin-bottom: 15px;" src="cid:ugly.png" width="128" height="128" /> Какой-Ρ‚ΠΎ тСкст Π²ΠΎΠΊΡ€ΡƒΠ³ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ. Какой-Ρ‚ΠΎ тСкст Π²ΠΎΠΊΡ€ΡƒΠ³ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ. Какой-Ρ‚ΠΎ тСкст Π²ΠΎΠΊΡ€ΡƒΠ³ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ. Какой-Ρ‚ΠΎ тСкст Π²ΠΎΠΊΡ€ΡƒΠ³ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ. </p> </div> '; $from = "test@test.com"; $to = "zhenikipatov@yandex.ru"; $subject = "Π’Π΅ΠΌΠ° письма"; // Π—Π°Π³ΠΎΠ»ΠΎΠ²ΠΊΠΈ письма === >>> $headers = "From: $from\r\n"; //$headers .= "To: $to\r\n"; $headers .= "Subject: $subject\r\n"; $headers .= "Date: " . date("r") . "\r\n"; $headers .= "X-Mailer: zm php script\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: multipart/alternative;\r\n"; $baseboundary = "------------" . strtoupper(md5(uniqid(rand(), true))); $headers .= " boundary=\"$baseboundary\"\r\n"; // <<< ==================== // Π’Π΅Π»ΠΎ письма === >>> $message = "--$baseboundary\r\n"; $message .= "Content-Type: text/plain;\r\n"; $message .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $message .= "--$baseboundary\r\n"; $newboundary = "------------" . strtoupper(md5(uniqid(rand(), true))); $message .= "Content-Type: multipart/related;\r\n"; $message .= " boundary=\"$newboundary\"\r\n\r\n\r\n"; $message .= "--$newboundary\r\n"; $message .= "Content-Type: text/html; charset=utf-8\r\n"; $message .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $message .= $text . "\r\n\r\n"; // <<< ============== // прикрСпляСм Ρ„Π°ΠΉΠ»Ρ‹ ===>>> foreach($attach as $filename){ $mimeType='image/png'; $fileContent = file_get_contents($filename,true); $filename=basename($filename); $message.="--$newboundary\r\n"; $message.="Content-Type: $mimeType;\r\n"; $message.=" name=\"$filename\"\r\n"; $message.="Content-Transfer-Encoding: base64\r\n"; $message.="Content-ID: <$filename>\r\n"; $message.="Content-Disposition: inline;\r\n"; $message.=" filename=\"$filename\"\r\n\r\n"; $message.=chunk_split(base64_encode($fileContent)); } // <<< ==================== // Π·Π°ΠΊΠ°Π½Ρ‡ΠΈΠ²Π°Π΅ΠΌ Ρ‚Π΅Π»ΠΎ письма, дописываСм Ρ€Π°Π·Π΄Π΅Π»ΠΈΡ‚Π΅Π»ΠΈ $message.="--$newboundary--\r\n\r\n"; $message.="--$baseboundary--\r\n"; // ΠΎΡ‚ΠΏΡ€Π°Π²ΠΊΠ° письма $result = mail($to, $subject, $message , $headers); var_dump($result); 

    Inserts pictures as attachments and sends an email. All images inserted in the letter using src = "cid: filename.type" are not shown as attachments.

    There is also an example in the book PHP5 in practice, in chapter 16.1 the sending of emails is described in detail, including the insertion of pictures into the text (Listing 16.1.4).

    • Although the link can find the answer to the question, it is better to point out the most important thing here, and give the link as a source. If the page to which the link leads will be changed, the response link may become invalid. - From the queue of checks - Streletz
    • Corrected the answer, added a code and a small explanation. - vfedorov_ru

    There is one simple method, without any attachments) If the picture is on your server, then you can simply register a link for it and it will be pulled from your server.

     <IMG border=0 src="http://site.com/img/image.jpg" width=800 height=1964 useMap=#FPMap0> 
    • Did you even read the question ??? - KARTOH

    You transform a picture into base64 and insert it as a data-uri.