Can someone take a look at this code and help me out.
I am trying to get 2 CSV files attached to one email:
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$to = "$name <$email>";
$from = "Account Upsert Process";
$subject = "Here is your attachment";
$fileatt = "/users/msimonds/public_html/sforce/samples/accounts_created.csv";
$fileatttype = "application/csv";
$fileattname = "accounts_created.csv";
$fileatt2 = "/users/msimonds/public_html/sforce/samples/accounts_updated.csv";
$fileatttype2 = "application/csv";
$fileattname2 = "accounts_updated.csv";
$headers = "From: $from";
$file = fopen($fileatt, 'rb');
$data = fread($file, filesize($fileatt));
fclose($file);
$file2 = fopen($fileatt2, 'rb');
$data2 = fread($file2, filesize($fileatt2));
fclose($file2);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
$data = chunk_split(base64_encode($data));
$data2 = chunk_split(base64_encode($data2));
$message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatttype};\n" . " name=\"{$fileattname}\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"{$fileattname}\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n";
$message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatttype2};\n" . " name=\"{$fileattname2}\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"{$fileattname2}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .$data . $data2 . "\n\n" ."--{$mime_boundary}--\n";
if (mail($to, $subject, $message, $headers))
{
echo "<p>The email was sent.</p>";
}
else
{
echo "<p>There was an error sending the mail.</p>";
}
I tried to search the web to see some sort of tutorial, but cannot find anything but something like the above code
TIA,
Mike Simonds