我有动态生成的html2canvas图像,并通过uniqid函数命名。用户创建他们的图像,被发送到预览屏幕并确认提交。
我在将html2canvas图像附加到正在发送的电子邮件时遇到问题。图像将保存在服务器上并发送电子邮件,但附加的图像数据为零。任何意见是极大的赞赏!
这是评论和发送页面:
<?php
session_start();
$filteredData=substr($_POST['img_val'], strpos($_POST['img_val'], ",")+1);
$unencodedData=base64_decode($filteredData);
file_put_contents(uniqid() . '.png', $unencodedData);
$_SESSION['question'] = $imgValue;
?>
<table>
<tr>
<td colspan="2">
<br />
<br />
<br />
<form id="form1" name="form1" method="post" action="mailer2.php">
<table width="455" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="175" height="44" align="center"><label for"name">Name</label></td>
<td width="280"><input name="name" type="text" id="name" size="30" />
</td>
</tr>
<tr>
<td height="45" align="center"><label for="email">Email</label></td>
<td><input name="email" type="text" id="email" size="30" /></td>
</tr>
<tr>
<td height="41" align="center"><label for="question">Preview</label></td>
<td><span name="question" id="question"><?php echo '<img width="500px" src="'.$_POST['img_val'].'" />';
?></span></td>
</tr>
<tr>
<td height="38"> </td>
<td><label>
<input type="submit" name="Submit" id="Submit" value="Submit" />
</label></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
...和发送页面:
<?php
session_start();
require_once 'class.phpmailer.php';
$imgValue = $_SESSION['question'];
$mail = new PHPMailer();
$body = "</pre>
<div>";
$body .= "This is the email body text" ;
$body .= "</div>" ;
$mail->AddAddress("michael.y@informinteriors.com");
$mail->Subject = "Endless Configuration Submission";
$mail->MsgHTML($body);
$mail->AddStringAttachment($imgValue, $imgValue, 'base64', 'image/png');
if(!$mail->Send()) {
echo "There was an error sending the message. Please try again.";
exit;
}
echo "Configuration was sent successfully";
?>