如何在cakephp3中使用base64编码图像发送邮件

时间:2016-08-13 12:24:12

标签: php cakephp-3.0

我正在尝试从cakephp3发送邮件。 代码是:

$msg = <span style="font-weight: bold; color: rgb(11, 83, 148);">Hello</span><div><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHIAAAAQCAYAAADK4SssAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAhdEVYdENyZWF0aW9uIFRpbWUAMjAxNjowNzowNSAxNToyNDo1M3EAmwgAAAU2SURBVFhH7VhLb1tFGD2+7+v3I05xmzYQiEJfCx4CCVSxZIkEKzb8ElbwK1iC1BXqnwhCYsUCFXURpBInjvtKUtvX9n3anG/uvXFC22VCkXySq3l9883jzJyZceHdO1/OH2zfw6+//Y6d/adYX+vggxvriOMES5wvojDE4fExKpUqyiUXBWg4eNZDqE3RKV+DrmvwPA9BEEIvFGA7NsZTHy7DcqUMXdNxeHiIfr+PjMifMRyMVMUkSRAtSbwQFEiOphUwn80xm89VnpAThRHmhTkMw1A2/EdWTLIZ5zebzVhXw9HR0Wki7zHjGEXdyEyX+E+RU5CR9zIEs4RkI9uRBwsiE27zu70HsDUhc4nXGULiZ601XCvW0O3to9vtLogcjD3c2v4JTdNWCyHfwoI597XG/S3bW7Z5mpeGeZoCoOQhTadxqsZJXKIiE6eXGRWFEDtNhWmdtB0J4znlI2tA/AtmzJO45CdiSEg74suQukynX1ZG25nE+S/tS77qhRQzIj6UDf1K56VMziOB+BTfWTPKPi1J29DZ7zx9kRjGIb7f+gRfX72F3f3uWSJHkzE+/OUuPmquUX8jRByYQb1OyH7DKuE4nKBk6BjEMWwOwKEMyySIXUwbj86vcIUMwinzZ7jkVPAoGNNXgrZd5AxoeDwdoWhYnKAEMadgxXKp8zoOvEMUzRJWeYjvjkdYsR3sMXy/sYqHE57d7LwvBPLrFKvwogBPgik23DIi+jmOIlxm3fuDpzB1Cw592vyE2KPQR81y1LHxzB+jzrF4HF+NDE3Jxlapjn4wwRtOGX4SI2J/e5MB7wsWWpaJvYmHummRbA0B+x3xbJKF4dLf/mSo5iBdoOcLtZYStsw7jKfN8e3mx/jqyvUTImUrnEBW35PAw83KJQ6shKtuCVuVFlqc2GEccGJM3Kw2MIojklZRZEVJhNv1FbRMhxPm4p1yE6u2S8JDvOlWsVFuoMFd/iwMcL1KX5aFjlvBNbcGi/5ksjYrTZIxJWEGbtRWUDMcku9iykl9u1xlW7zVGWJrY8SLwFWmizzoZXHItcxnf5q0d7Jjoe3U8F69hfVimcS52Cw11AJydB3PY94ISdoq+2ZzvHsk4+/xAAckWXbrcy7YKRfMMPJhFgxcr7VR0U2SHysyb9fb7OMqXE5WrhYXBVEKI4wXsnAKp6R1jNvbPypCZJeJaMgqyKXIUJPGFDPFoew6gciLSKCESp4IddNimEpnirRO6us0UglkB7PyPC2TlN7k8jQDVTuVYNUe45IjrUkfTOYJJD+mjYxB6qXSvph4SctfLulil7ctNrlgig8pz+tKudgJpH0ZU2p5gWCbQyrSd1ufUlpvviitURDgh90/1KrOxrvEawqf8vp5ex0blQb2er2zRPq+T+kxM9MlXnfElPoZd5y8IV8gcon/F+QHgZzIM5cd+WUnl9VcXV8ls5J/Yvsvm1dUWeIccUKkkPhgZxfTIIFjWwh4O5TQmwSwebO05DMN5lF+eeBLvh+EsAyNdWJVJnamXsBoGizJvGAsLju8Cf2120e/9xiTmcareYwQJoqFBAHDOPBRKlp42H+Ob764g529p7j/5w421i+h+2iITtPBw8djvNV2UG1fxuZak8+e9Ia3xPngtLQuiAxDEtlDZ7WF4diHbRT4RuShyjdayXVICh/kfGQHPEuvdNro7j9CFM9Rr5VOdp83DeGYGkrlEneqPOOXOE+8lEi57OgsUG+uM7rIRPZ2UmByxp0mTsRO4mKuXntZJH3/LXHeWBDZxT9ge5xX8mZK3gAAAABJRU5ErkJggg=="><span style="font-weight: bold; color: rgb(11, 83, 148);"><br></span></div>
$email = new Email('WebMail');
$email  ->template('contact','contact')
        ->emailFormat('both')
        ->from([$username => $senderName])
        ->to($email_to)
        ->replyTo($email_id)
        ->subject('Client Message');
        ->send($msg);

现在如何使用邮件正文中的文本显示base64编码图像。

1 个答案:

答案 0 :(得分:1)

只需将电子邮件类型设置为html,并将内容放入以下内容:

<img src="data:image/png;base64,YOUR_BASE64_CODE"/>