问题
I've read a few topics about this, already tried many of them, but none of them worked so far. So I'm kinda lost what to do now, it would be really important to display these images in the e-mail.
Here is a shortened version of my code:
require_once("class.phpmailer.php");
$body = '
<body style="margin: 10px auto;">
<table width="100%">
<tr>
<td width="360">
<img src="cid:trip_2" alt="trip_2">
<!--<img src="trip_2.png" alt="trip_2">-->
</td>
</tr>
</table>
<table width="100%">
<tr>
<td align="right" width="360">
<img src="cid:pic" alt="pic">
<!--<img src="pic.png" alt="pic">-->
</td>
</tr>
</table>
<table width="100%">
<tr>
<td width="360">
<img src="cid:pub" alt="pub">
<!--<img src="pub.png" alt="pub">-->
</td>
</tr>
</table>
</div>
</body>';
$mail = new PHPMailer();
$mail->Host = "smtp.gmail.com";
$mail->Port = 25;
$mail->Username = "*****";
$mail->Password = '*****'
$mail->IsHTML(true);
$mail->Subject = "Please appear";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->SetFrom("example@example.com","Example");
$mail->AddReplyTo("example@example.com","Example");
$mail->AddAddress("example@example.com", "Example");
$mail->AddEmbeddedImage("trip_2.png", "trip_2","trip_2.png");
//$mail->AddAttachment("trip_2.png");
$mail->AddEmbeddedImage("pic.png", "pic","pic.png");
//$mail->AddAttachment("pic.png");
$mail->AddEmbeddedImage("pub.png", "pub","pub.png");
//$mail->AddAttachment("pub.png");
$mail->MsgHTML($body);
$mail->Send();
What I want to achieve is to display these 3 images in the e-mail, by default. So the user don't have to click "display images from this address" or something like that. Because without the images, the e-mail would be kinda empty, and we need some style in the e-mail.
Sorry about my grammar Guys, thank you for your time.
Mark
回答1:
In gmail: You can't without the user approving your imagery. It's an anti-spam/ anti-tracking technique that has to be off by default to work.
You can make Gmail display images (embedded into content) with authenticating emails sent. You just make sure you have a correct SPF record, and 1024 bit DKIM signed the message. Then gmail shows embedded images within content.
回答2:
This is not a limitation in the code. The limitation lies in user's e-mail client. By-passing this is not possible if not the user himself clicks on "Automatically show images from this sender" or something like that.
回答3:
Since December 2013, Gmail now shows inline images by default.
Users can still turn it off, though.
回答4:
I had the same problem before and here's how I resolved it. I used the same thing you did for images (AddEmbeddedImage + cid:name) but, when adding
require("PHPMailer_5.2.0/PHPMailerAutoload.php");
Instead of just the class, it worked.
Hope it helped.
来源:https://stackoverflow.com/questions/17989393/display-image-in-html-e-mail-with-php