【问题标题】:Sending Modified Images in PHP via Email通过电子邮件在 PHP 中发送修改后的图像
【发布时间】:2017-12-08 09:36:48
【问题描述】:

我正在编写一个脚本,该脚本可以打开表单的现有图像并填写表单。我已经输入了在表单中编写文本所需的所有代码。问题是我正在尝试将修改后的图像发送到电子邮件。我正在使用 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";  
}    

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

【问题讨论】:

    标签: php email email-attachments imagejpeg


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2018-09-20
      • 1970-01-01
      • 1970-01-01
      • 2012-04-24
      • 1970-01-01
      • 2012-06-29
      • 2012-07-03
      • 1970-01-01
      相关资源
      最近更新 更多