php发送电子邮件与图像 [英] php send email with image

查看:138
本文介绍了php发送电子邮件与图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试发送一封带有图片的电子邮件;我的电子邮件的正文是:

 <?php 

$ message =<< <电子邮件

< img src =http://planet-earth.bogus.us/icons/secret.pictures.gif>

亲爱的{$ email},

电子邮件;

?>

收到电子邮件时,我看不到图片。相反,I
请参阅< img src =http://planet-earth.bogus.us/icons/secret.pictures.gif> 。我知道这是因为<<电子邮件;我将如何使用<<<<电子邮件?



更新



我使用的是zend-framework。我的代码如下:

 <?php 
$ mail = new Zend_Mail();
$ mail-> setFrom('admin@mysite.com','我的网站');
$ mail-> addTo($ recoveryaccount-> username);
$ mail-> setSubject(Mysite);
包含_email_recover_password.phtml;
$ mail-> setBodyText($ message);
$ mail-> send();
?>

_include_email_recover_password.pthml
<?php

$ message =<<<电子邮件
< img src =http://picturelocation.picture.gif>
亲爱的{$ account-> getUsername()},

有人请求与此帐户相关联的密码为
重置。如果您发起此请求,请单击以下链接以完成此过程:

http://www.example.com/ {$ account-> getRecovery()}

谢谢!
Mysite

问题?联系我们admin@mysite.com

电子邮件;

?>


解决方案

要回答您的问题,您需要发送内容将内容类型设置为 text\html 的标题。没有它,您的消息被接收客户端视为纯文本。以下代码正确设置内容标题并发出一个基本的HTML消息。

  // message 
$ message = '
< html>
< body>
< img src =http://planet-earth.bogus.us/icons/secret.pictures.gif>
< / body>
< / html>
';

//添加内容标题
$ headers ='MIME-Version:1.0'。 \r\\\
;
$ headers。='Content-type:text / html; charset = iso-8859-1'。 \r\\\
;

$ headers。='至:David< david-z@domain.com>'。 \r\\\
;
$ headers。='From:Bot< bot@domain.com>'。 \r\\\
;

mail(david-z@domain.com,mysubject,$ message,$ headers);


I am trying to send an email with a picture; the body of my email is:

<?php 

$message = <<< email

<img src="http://planet-earth.bogus.us/icons/secret.pictures.gif">

Dear {$email},

email;

?>

When I receive the email, I can't see the picture. Instead, I see <img src="http://planet-earth.bogus.us/icons/secret.pictures.gif">. I know it's because of the <<< email; how would I be able to display the picture instead of the code using <<< email?

UPDATE

I am using zend-framework. My code looks like this:

<?php
     $mail = new Zend_Mail();
     $mail->setFrom('admin@mysite.com', 'My site');
     $mail->addTo($recoveryaccount->username);
     $mail->setSubject("Mysite");
     include "_email_recover_password.phtml";
     $mail->setBodyText($message);
     $mail->send();
?>

_include "_email_recover_password.pthml" 
<?php 

 $message = <<< email
 <img src="http://picturelocation.picture.gif">
 Dear {$account->getUsername()},

 Somebody has requested that the password associated with this account be
 reset. If you initiated this request, click the below link to complete the process:

 http://www.example.com/{$account->getRecovery()}

 Thank you!
 Mysite

 Questions? Contact us at admin@mysite.com

 email;

 ?>

解决方案

To answer your question, you need to send out content headers that sets the content type to text\html. Without it, your message is treated as plain text by the receiving client. The following code sets the content headers properly and sends out a basic HTML message.

// message
$message = '
<html>
<body>
  <img src="http://planet-earth.bogus.us/icons/secret.pictures.gif">
</body>
</html>
';

// Add the content headers
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= 'To: David <david-z@domain.com>' . "\r\n";
$headers .= 'From: Bot <bot@domain.com>' . "\r\n";

mail("david-z@domain.com", "mysubject", $message, $headers);

这篇关于php发送电子邮件与图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆