I am working on a script that opens an existing image of a form, and fills in the form. I have typed all of the code necessary to write the text in the form. The problem is that I am trying to send the modified image to email. I am using the GD library ImageCreate, ImageCopy and ImageJPEG. But instead of saving an image, the form is to be emailed. here's what I got so far
$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 protected]\r\n";
$emailheader .= "Reply-To: [email protected] \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("[email protected]", "Sample Subject", "", $emailheader)){
echo "success";
}else{
echo "failure";
}
The email is registered as having an attachment but it's blank. Also the plain test message isn't showing up.
I would really advise you to use libraries which are build for it.
You would get the job done way faster than trying to reimplement it yourself.