PHP:通过套接字发送带有图像附件的邮件


PHP: Send Mail with Image Attachment Through Socket

我需要用fsockopen发送一封附有一张图片的电子邮件。到目前为止,我一直使用这个代码:

http://tareq.wedevs.com/2010/01/sending-mail-with-gmails-smtp-server-with-fsockopen/

效果很好,但不会镶嵌图像。我该怎么做?我不能使用任何特殊的扩展/库,因为我无法访问服务器。

我试着只添加

<img src="data:image/jpg;base64,[IMAGE DATA] alt="IMG" />

但这似乎不起作用(它总是显示一个破碎的图像和文本"IMG")。我已将图像日期base64编码。有更好的方法吗?还是这样可以?如果这样可以,你知道为什么它可能不起作用吗?

PHP Mailer就是答案!

http://phpmailer.worxware.com/

你可以很容易地用以下行附加图像:

$mail->AddStringAttachment(base64_decode($IMG), "picture.jpg", "base64", "image/jpeg");