2011-05-27 54 views

回答

1
if(!empty($_POST['email'])){ 
    $email=$_POST['email']; 
    $image=$_POST['legoImage']; 
    $headers="From:".$email."\r\n"; 
    $headers .= "MIME-Version: 1.0\r\n"; 
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
    list($settings, $encoded_string) = explode(',', $image); 
    list($img_type, $encoding_method) = explode(';', substr($settings, 5)); 

    if($encoding_method == 'base64'){ 
     $file=fopen("images/newLego.png",'w+'); 
     fwrite($file,base64_decode($encoded_string)) ; 
     fclose($file); 
    } 
    $my_file = "newLego.png"; 
    $my_path = "images/"; 
    $my_subject = "My Design"; 
    $my_message = "Designed by ".$email; 
    mail_attachment($my_file, $my_path, "[email protected]", $email, $email, $email, $my_subject, $my_message);   
} 

我拿起mail_ attachment()函数here

0

假设您已经使用您发布的教程成功创建了画布的图像文件,则可以使用PEAR的Mail_Mime这样的库将附件添加到您的电子邮件中。

对于使用Mail_Mime的示例,可以参考this问题。

+0

问题是;如何将图像传送到服务器。据我所知,它仍然在客户端。 – 2011-05-27 10:35:00

+0

@berry是的..我的问题在于将图像发送到服务器而不让用户处理它。 – Rohan210 2011-05-27 10:38:48

6

我想你需要一些javascript魔术,而且因为你已经使用了HTML5 canvas,所以这不应该是个问题。

因此,提交按钮上的onclick事件将向您的后端php邮件程序脚本发出ajax请求。

var strDataURI = oCanvas.toDataURL(); 
// returns "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACt..." 

你只需要传递strDataURI作为参数。 现在,我想你也应该保存这些在你的数据库,以便电子邮件可以只包含这里面的图片标签:

<img src="http://www.yourdomain.com/generate_image.php?id=2" alt="Design #2" /> 

而且该generate_image.php脚本会做这样的事情

<?php 

header('Cache-control: max-age=2592000'); 
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 2592000)); 

// connect to db here .. 
// $id = (int)$_GET['id']; "SELECT youtable WHERE id = '{$id}'" 
// and the $image variable should contain "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACt..." 

list($settings, $encoded_string) = explode(',', $image); 
list($img_type, $encoding_method) = explode(';', substr($settings, 5)) 

header("Content-type: {$img_type}"); 

if($encoding_method == 'base64') 
    die(base64_decode($encoded_string)); // stop script execution and print out the image 

else { // use another decoding method 
} 
+0

@highstrike ...不幸的是,图像是在客户端创建的,我想将其发送到服务器端。它不在我的服务器 – Rohan210 2011-05-27 10:45:00

+1

是的,我知道,这就是为什么你必须在提交按钮上做出这个Ajax请求,以便你从客户端传递“data:image/png; base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACt ...”到你的服务器。使用jQuery for ajax或其他库 – Highstrike 2011-05-27 10:49:10

+0

好吧,我会看看那是怎么回事! – Rohan210 2011-05-27 10:51:21

相关问题