[英]PHP PEAR MAIL Not working with base64 image or dataurl
I am trying to send dynamically created canvas object as an embedded image in mail.For that i have converted canvas to dataurl and given it to mailer library. 我正在尝试将动态创建的画布对象作为嵌入式图像发送到mail。为此,我已将画布转换为dataurl并将其提供给邮件库。 Unfortunately it is not working with dataurl. 不幸的是,它不适用于dataurl。
I tried with src having actual path and it worked but dataurl is having issue. 我尝试使用具有实际路径的src进行工作,但dataurl存在问题。
<?php
require_once "Mail.php";
require_once 'Mail/mime.php';
$from = "xyz@gmail.com";
$subject = $_REQUEST['subject'];
$data=$_REQUEST['data']; //dataurl
$img = $_REQUEST['body'];
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "myaccount@gmail.com";
$password = "mypassword";
$to="someone@xyz.com";
$body="<html><body><h1>Report is Here</h1><img src='cid:whatever'/></body></html>";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mime = new Mail_mime("\n");
$mime->setTXTBody("");
$mime->addHTMLImage($data, "image/png","1234.png",false,"whatever");
$mime->setHTMLBody($body);
$body = $mime->get();
$headers = $mime->headers($headers);
$mail = $smtp->send($to, $headers, $body);
;
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("Message successfully sent");
echo "<img src='data:image/png;base64,".$data."'/>";
}
?>
Mail sent successfully and image too rendered as i have put code at last but it doesn't appear in mail. 邮件已成功发送,并且图像也已渲染,因为我最后放置了代码,但它没有出现在邮件中。
You are passing a string, while addHTMLImage
expects a file name or the binary contents. 您正在传递字符串,而addHTMLImage
需要文件名或二进制内容。
Either store it in a temporary file and pass that path, or decode the base64 encoded data to binary, and pass that. 可以将其存储在一个临时文件中并传递该路径,或者将base64编码的数据解码为二进制并传递。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.