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="" 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 , , ...).

    • >> 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( '', '' ); // чтобы отображалась картинка и ее не было в аттаче // путь к картинке задается через 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 = ""; $to = ""; $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="" 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.