PHP help

edited November 2010 in Internet & Media
Hi Guys

I have a Flash/php form that sends mail to multiple email accounts that are stored in a txt file. but that part is not the issue.

My problem is that i want a jpg file send with it. the jpg wil always be the same one and is already on the server.

i got it to send the file but now the attached image is 0 kb in size and obviously cant open. i think it may be the encoding (base64) but i cant seem to figure it out.

here is my code:

<?php

//initialize the mail variable
//subject must not contain Newline or it wont work as expected
$subject = "Newsletter from Cityscene Interactive Media";
$message = StripSlashes($message);
$boundary = md5(date('r', time()));

//Initial Headers
$headers = "MIME-Version: 1.0\r\n"; // <- the "\r\n" indicate a carriage return and newline, respectively
$headers .= "From: My Form <me@mydomain.co.za>\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=" . $boundary . "\r\n"; // <- This is
// saying the there will be more than one (a "mix") of Content Types in this email.
// The "boundary" value will indicate when each content type will start

//First Content Type
$message = "\r\n\r\n--" . $boundary . "\r\n"; // <- This indicates that I'm going to start
// declaring headers specific to this section of the email.
// MAKE SURE there's only ONE(1) "\r\n" between the above boundry and the first header below (Content-Type)
$message .= "Content-type: text/plain; charset=\"iso-8859-1\"\r\n"; // <- Here I'm saying this content should be plain text
$message .= "Content-Transfer-Encoding: 7bit\r\n\r\n";

// Body of the email for the headers I just declared
$message .= "HERE IS SOME NEW INFO:\r\n";
$message .= "News: ".$_POST;

//Second Content Type
$message .= "\r\n\r\n--" . $boundary . "\r\n"; // <- This idicates that I'm going to start
// declaring some more headers for the content below
// MAKE SURE there's only ONE(1) "\r\n" between the above boundry and the first header below (Content-Type)
$message .= "Content-type: image/jpeg\r\n"; // <- Here I'm saying that this Content Type is for a JPEG image
$message .= "Content-Transfer-Encoding: base64\r\n"; // <- this is saying that this section's content will be base64 Encoded
$message .= "Content-Disposition: attachment; filename=\"logo.jpg\"\r\n"; // <- This is saying the content below should be an attachment and gives it a file name

// The base64_encode below is necessary because this is a file.
$message .= base64_encode(file_get_contents($_FILES["picture"]["tmp_name"]));

$message .= "\r\n\r\n--" . $boundary . "--"; // <- This indicates the end of the boundries. Notice the additional "--" after the boundry's value.

//getting mail recipients from the subscribe.txt
$fileName = "subscribe.txt"; // File which holds all data
$arrFp = file($fileName); // Make array of file content lines
$numAdds = count($arrFp); // Count no. of elements in the array, count email addresses

//Now we send mail to EACH recipient
$count = 0;
for($i=0; $i<$numAdds; $i++)
{
$emailAddress = trim($arrFp[$i]); // Trim email addresses before sending mails
$success = mail($emailAddress, $subject, $message, $headers);
}

?>
Sign In or Register to comment.