保存后通过电子邮件发送图片

时间:2014-02-06 19:38:18

标签: php email canvas

我有一个我要保存到服务器的画布,通过电子邮件发送图片的最佳方式 - 附加或嵌入 - 我刚刚添加了一些@mail代码,但我认为应该有一个更有效的方式,因为我已经传输编码的base64文件。我不知道如何传递电子邮件的名称和名称以及文件,我是PHP的初学者, 这是我的代码:

<?php
   $data = $_POST['canvasData'];

//$file = "/path/to/file.png";    $file = "canvases/file.png";
iterator_count(new DirectoryIterator('canvases'));
$file = "canvases/file_" . iterator_count(new DirectoryIterator('canvases')).".png";

$uri =  substr($data,strpos($data,",")+1);
$uri = str_replace(' ','+',$uri);
file_put_contents($file, base64_decode($uri));

echo $file;


$to =   'info@ventoline.co.uk';
$subject =  'test receive a drawn msg from  ventoline www';
$bound_text =   "euhh?";
$bound =    "--".$bound_text."\r\n";
$bound_last =   "--".$bound_text."--\r\n";

$headers =  "From: admin@server.com\r\n";
$headers .=     "MIME-Version: 1.0\r\n"
."Content-Type: multipart/mixed; boundary=\"$bound_text\"";

$message .=     "If you can see this MIME than your client doesn't accept MIME types!\r\n"
.$bound;

$message .=     "Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n"
."hey my <b>good</b> friend here is a picture of regal beagle\r\n"
.$bound;

$file =     file_get_contents($file);

$message .=     "Content-Type: image/jpg; name=\"regal_004.jpg\"\r\n"
."Content-Transfer-Encoding: base64\r\n"
."Content-disposition: attachment; file=\"regal_004.jpg\"\r\n"
."\r\n"
.chunk_split(base64_encode($file))
.$bound_last;

if(mail($to, $subject, $message, $headers))
{
    echo 'MAIL SENT';
} else {
    echo 'MAIL FAILED';
}
?>

它返回'MAIL SENT',但我还没有收到任何信息。

0 个答案:

没有答案