Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中嵌入二进制图像发送电子邮件_Php_Image_Symfony_Binary_Swiftmailer - Fatal编程技术网

在php中嵌入二进制图像发送电子邮件

在php中嵌入二进制图像发送电子邮件,php,image,symfony,binary,swiftmailer,Php,Image,Symfony,Binary,Swiftmailer,我试图发送带有图像的电子邮件,但我的服务器中只有二进制代码。 知道怎么做吗 现在我发送的html是这样的(以Base64编码): 我正在使用Symfony2的SwiftMailer库发送电子邮件 完整的示例代码(二进制代码中有剪切): //参数 $subject=“演示电子邮件”; $body=” 产品名称 代码3089 14.70$ "; $name=“客户名称”; $email=”clientmail@domain.com"; $from_地址=”mail@domain.com"; $f

我试图发送带有图像的电子邮件,但我的服务器中只有二进制代码。 知道怎么做吗

现在我发送的html是这样的(以Base64编码):


我正在使用Symfony2的SwiftMailer库发送电子邮件

完整的示例代码(二进制代码中有剪切):

//参数
$subject=“演示电子邮件”;
$body=”
产品名称
代码3089
14.70$

"; $name=“客户名称”; $email=”clientmail@domain.com"; $from_地址=”mail@domain.com"; $from_name=“应用程序名称”; //SwiftMessag对象 $message=\Swift\u message::newInstance() ->setSubject($subject) ->setFrom(数组($from\u address=>$from\u name)) ->setTo(数组($email=>$name)) ->setBody($body,'text/html'); //发送电子邮件 $this->get('mailer')->send($message);
我在一封电子邮件中嵌入了一张带有以下代码的图像:

$message = \Swift_Message::newInstance();

$body = '<html><head></head><body>'.
    '<p><img src="'.$message->embed(\Swift_Image::fromPath(
        \Swift_Attachment::fromPath([full path to you image]
    )
    ->setDisposition('inline'))).'" alt="Image" /></p>'.
    '</body></html>'
;

$message
    ->setSubject('Subject')
    ->setFrom($from)
    ->setTo($to)
    ->setBody(
        $body,
        'text/html'
    )
;

$this->mailer->send($message);
$message=\Swift\u message::newInstance();
$body=''。
“嵌入(\Swift\u Image::fromPath(
\Swift_附件::fromPath([您图像的完整路径]
)
->setDisposition('inline'))。“alt=”Image“/>

”。 '' ; $message ->setSubject(‘Subject’) ->setFrom($from) ->setTo($to) ->挫折体( $body, “文本/html” ) ; $this->mailer->send($message);

[图像的完整路径]
替换为图像的路径,例如
dirname(\uu文件\uu)../../images/image.png'

是的,这是使用绝对路径发送图像的方法。但是,我的问题是,我是否可以发送图像二进制文件,因为图像文件不在我的服务器中,而这些服务器只返回二进制代码。有什么办法吗?@jpintor很抱歉,这对您没有帮助。您可以尝试将二进制代码保存到您的服务器上吗是的,我可以将图像保存在一个文件中,但我想避免它。但是,我会尝试这样做,稍后删除该文件。我刚刚看到
数据:
是重复的。你能尝试只使用一个
数据:
?好的,从复制/粘贴中发出,但在项目中没有重复。这不是问题。如何解决o您将此图像发送给Swiftmailer?请显示完整代码。
//params
$subject = "Demo e-mail";
$body = "<html>
    <table>
        <tr>
            <td>
                <img src='data:image/png; base64, iVBORw0KGgo...zIIAAAAASUVORK5CYII='>
            </td>
            <td style='padding-left:20px'>
                <div>
                    <h3>Product name</h3>
                    <h4>Code 3089</h4>
                    <p>14.70 $</p>
                </div>
              </td>
        </tr>
    </table>
    </html>";
$name = "Client name";
$email = "clientmail@domain.com";
$from_address = "mail@domain.com";
$from_name = "App Name";

//SwiftMessag eobject 
$message = \Swift_Message::newInstance()
        ->setSubject($subject)
        ->setFrom(array($from_address => $from_name))
        ->setTo(array($email => $name))
        ->setBody($body, 'text/html');

//send email
$this->get('mailer')->send($message);
$message = \Swift_Message::newInstance();

$body = '<html><head></head><body>'.
    '<p><img src="'.$message->embed(\Swift_Image::fromPath(
        \Swift_Attachment::fromPath([full path to you image]
    )
    ->setDisposition('inline'))).'" alt="Image" /></p>'.
    '</body></html>'
;

$message
    ->setSubject('Subject')
    ->setFrom($from)
    ->setTo($to)
    ->setBody(
        $body,
        'text/html'
    )
;

$this->mailer->send($message);