我正在尝试使用下面的代码使用PHP在body64上发送带有base64图像的电子邮件,但图像永远不会出现...如果我更改为URL它可以工作,但它不适用于base64 ..我只用<img src=base64>在新页面上测试了base64,并且也工作了......我错过了什么?
<?php // recipients $to = $_POST['email']; // subject $subject = 'Test'; // message $message = ' <html> <head> <title>Test</title> </head> <body> <img src="'.$_POST['imageFromOtherPage'].'"/> </body> </html> '; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Mail it mail($to, $subject, $message, $headers); ?>这是我的base64图像示例: http : //jsfiddle.net/28nP4/
I'm trying to send an email with an image in base64 on the body with PHP using the code below, but the image never appears... If I change to an URL it works, but it doesn't with the base64... I tested the base64 on a new page only with <img src=base64> and worked too... What am I missing??
<?php // recipients $to = $_POST['email']; // subject $subject = 'Test'; // message $message = ' <html> <head> <title>Test</title> </head> <body> <img src="'.$_POST['imageFromOtherPage'].'"/> </body> </html> '; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Mail it mail($to, $subject, $message, $headers); ?>Here is my base64 image example: http://jsfiddle.net/28nP4/
最满意答案
我尝试了不同的东西,我找到的唯一方法是上传图片并获取URL,我从这个链接获得了这个: http : //j-query.blogspot.in/2011/02/save-base64-encoded-canvas-图像到png.html
这很简单:
<?php // requires php5 define('UPLOAD_DIR', 'images/'); $img = $_POST['img']; $img = str_replace('data:image/png;base64,', '', $img); $img = str_replace(' ', '+', $img); $data = base64_decode($img); $file = UPLOAD_DIR . uniqid() . '.png'; $success = file_put_contents($file, $data); print $success ? $file : 'Unable to save the file.'; ?>这会生成一个URL,因此,我使用生成的URL,而不是使用<img src="'.$_POST['imageFromOtherPage'].'"/> 。 工作得很完美!
I tried different things and the only way I found was uploading the image and getting the URL, I got that from this link: http://j-query.blogspot.in/2011/02/save-base64-encoded-canvas-image-to-png.html
It is very simple:
<?php // requires php5 define('UPLOAD_DIR', 'images/'); $img = $_POST['img']; $img = str_replace('data:image/png;base64,', '', $img); $img = str_replace(' ', '+', $img); $data = base64_decode($img); $file = UPLOAD_DIR . uniqid() . '.png'; $success = file_put_contents($file, $data); print $success ? $file : 'Unable to save the file.'; ?>And this generates an URL, so, instead of using <img src="'.$_POST['imageFromOtherPage'].'"/>, I use the generated URL. Worked perfectly!
更多推荐
发布评论