0

我正在编写一个脚本,该脚本打开表单的现有图像并填写表单。我已经输入了在表单中编写文本所需的所有代码。问题是我正在尝试将修改后的图像发送到电子邮件。我正在使用 GD 库 ImageCreate、ImageCopy 和 ImageJPEG。但不是保存图像,而是通过电子邮件发送表单。这是我到目前为止得到的

$tempname = "forms/temp".mt_rand().".jpg";
imagejpeg($image, $tempname);
$datamsg = chunk_split(base64_encode(file_get_contents($tempname)));
$uid = md5(uniqid(time()));

$message = "Please see attachment for your form";

$emailheader = "From: email@address.com\r\n";
$emailheader .= "Reply-To: email@address.com \r\n"; 
$emailheader .= "MIME-Version: 1.0\r\n";

$emailheader .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n"; 
$emailheader .= "This is a multipart message in Mime-Format\r\n";

$emailheader .= "--" .$uid."\r\n";
$emailheader .= "Content-Type: text/plain;\r\n";   
$emailheader .= "Content-Transfer-Encoding: 7bit\r\n"; 
$emailheader .= $message ."\r\n"; 
$emailheader .= "--" .$uid."\r\n"; 
$emailheader .= "Content-Type: Image/JPEG;name=\"jtstemp.jpg\"\r\n"; 
$emailheader .= "Content-Transfer-Encoding: base64\r\n"; 
$emailheader .= "Content-Disposition: attachment; Filename=\"jtstemp.jpg\"\r\n"; 
$emailheader .= $datamsg."\r\n";

if(mail("recipient@address.com", "Sample Subject", "", $emailheader)){
  echo "success";
}else{
   echo "failure";  
}    

该电子邮件已注册为带有附件,但它是空白的。也没有显示简单的测试消息。

4

1 回答 1

0

我真的建议您使用为其构建的库。

你会比尝试自己重新实现它更快地完成工作。

于 2017-07-04T21:13:13.570 回答