Hej - Jeg laver et nyhedsbrev i html som skal sendes via mail(). Jeg vil gerne kunne lave inline-billeder i så de ikke bliver blokeret af email-programmet outlook?
- det er der nogen som har et script der virker så
Det er noget i stil med <img style="width: 112px; height: 19px;" alt="" src="cid:logobillede"> for de billeder som er i nyhedsbrevet. -
Jeg har prøvet at arbjede med dette script som jeg har fra mail()-funktionens forum på php.net, men kan ikke få det til at virke med andet end attachment. Nogen gode bud?
<?php
$boundary = '-----=' . md5( uniqid ( rand() ) );
?>
<?php
$message .= "Content-Type: text/html; charset=UTF-8\\n";
$message .= "Content-Transfer-Encoding: base64\\n";
$message .= "Content-Disposition: inline; filename=\\"test.jpg\\"\\n\\n";
?>
When adding a file you must open it and read it with fopen and add the content to the message:
<?php
$path = "SHL/pics";
$fp = fopen($path, 'r');
do //we loop until there is no data left
{
$data = fread($fp, 8192);
if (strlen($data) == 0) break;
$content .= $data;
} while (true);
$content_encode = chunk_split(base64_encode($content));
$message .= $content_encode . "\\n";
$message .= "--" . $boundary . "\\n";
?>
Add the needed headers and send!
<?php
$headers = "From: \\"jeppe\\"<jeppe@bitboks.dk>\\n";
$headers .= "MIME-Version: 1.0\\n";
$headers .= "Content-Type: multipart/mixed; boundary=\\"$boundary\\"";
mail('jeppe@bitboks.dk', 'Email with attachment from PHP', $message, $headers);
?>
<?php
$boundary = '-----=' . md5( uniqid ( rand() ) );
?>
You can attach a Word document if you specify:
<?php
$message .= "Content-Type: application/msword; name=\\"my attachment\\"\\n";
$message .= "Content-Transfer-Encoding: base64\\n";
$message .= "Content-Disposition: attachment; filename=\\"$theFile\\"\\n\\n";
?>
When adding a file you must open it and read it with fopen and add the content to the message:
<?php
$path = "whatever the path to the file is";
$fp = fopen($path, 'r');
do //we loop until there is no data left
{
$data = fread($fp, 8192);
if (strlen($data) == 0) break;
$content .= $data;
} while (true);
$content_encode = chunk_split(base64_encode($content));
$message .= $content_encode . "\\n";
$message .= "--" . $boundary . "\\n";
?>
Add the needed headers and send!
<?php
$headers = "From: \\"Me\\"<me@here.com>\\n";
$headers .= "MIME-Version: 1.0\\n";
$headers .= "Content-Type: multipart/mixed; boundary=\\"$boundary\\"";
mail('myAddress@hotmail.com', 'Email with attachment from PHP', $message, $headers);
?>
Finally, if you add an image and want it displayed in your email, change the Content-Type from attachment to inline:
<?php
$message .= "Content-Disposition: inline; filename=\\"$theFile\\"\\n\\n";
?>
Indlæg senest redigeret d. 25.05.2007 10:07 af Bruger #11882