Quote:
So I have been trying to get this to work all day. I can't get a local
file on my web server to attach to an email. Right now I have it
printing out in the body of the email. Please help me with any
thouhgts on how to get it in as an attachment.
>
CODE:
<?php
>
>
ini_set(SMTP, "172.18.1.65");
ini_set(smtp_port, "25");
>
$engineer_email = $_REQUEST['engineer_email'] ;
$recipient = $_REQUEST['engineer_email'] ;
$PM_email = $_REQUEST['PM_email'] ;
$email = $PM_email;
$customer_name = $_REQUEST['customer_name'];
$customer_street_address = $_REQUEST['customer_street_address'];
$customer_name = $_REQUEST['customer_name'];
$individual_name = $_REQUEST['individual_name'];
$customer_city = $_REQUEST['customer_city'];
$customer_state = $_REQUEST['customer_state'];
$customer_phone = $_REQUEST['customer_phone'];
$individual_email = $_REQUEST['individual_email'];
>
$day = $_REQUEST['day'];
$dayofweek = $_REQUEST['dayofweek'];
$month = $_REQUEST['month'];
$day = $_REQUEST['day'];
$year= $_REQUEST['year'];
$time = $_REQUEST['time'];
>
$cust_confirmed = $_REQUEST['cust_confirmed'];
$hardware_confirmed = $_REQUEST['hardware_confirmed'];
$ss_confirmed = $_REQUEST['ss_confirmed'];
$hours_left = $_REQUEST['hours_left'];
$time_sheet = $_REQUEST['time_sheet'];
>
$ob = "----=_OuterBoundary_000";
$ib = "----=_InnerBoundery_001";
>
>
//CHECKS
if( empty($recipient) || empty($PM_email) ||
empty($hardware_confirmed) || empty($customer_name) ||
empty($customer_street_address) || empty($customer_name) ||
empty($individual_name) || empty($customer_city) ||
empty($customer_state) || empty($customer_phone) || empty($day) ||
empty($dayofweek) || empty($month) || empty($year) || empty($time)
|| empty($cust_confirmed) || empty($ss_confirmed )) {
>
echo "You did not supply all the necessary fields. Please use the back
button and complete.";
exit;
}
>
>
>
if( $ss_confirmed == "no") {
echo "You did not supply answer yes to 'Spreadsheet schedule in
black.' You must use this tool only when those are completed";
exit;
}
>
if( $cust_confirmed == "no") {
echo "You did not supply answer yes to 'Customer confirmed'. You must
use this tool only when those are completed";
exit;
}
>
//HERE WE MAKE THE VCAL FILE
>
$myFile = "dispatch.ics";
>
$fh = fopen("$myFile", "x+");
>
>
>
$stringData = "BEGIN:VCALENDAR\n";
$stringData .= "PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//
EN\n";
$stringData .= "VERSION:2.0\n";
$stringData .= "METHOD:PUBLISH\n";
$stringData .= "BEGIN:VEVENT\n";
$stringData .= "ORGANIZER:MAILTO:Administrator@exchange.org\n ";
$stringData .= "DTSTART:20060306T050000Z\n";
$stringData .= "DTEND:20060306T053000Z\n";
$stringData .= "LOCATION:location\n";
$stringData .= "TRANSP:OPAQUE\n";
$stringData .= "SEQUENCE:0\n";
$stringData .= "UID:
040000008200E00074C5B7101A82E0080000000020DC2A1392 43C60100000000000000000000DEF81CB498E1594B90378312 C3D6551D
\n";
$stringData .= "DTSTAMP:20060309T045649Z\n";
$stringData .= "DESCRIPTION:FreeFormText.\nMore FreeFormText.\n\n";
$stringData .= "SUMMARY:subject\n";
$stringData .= "PRIORITY:5\n";
$stringData .= "X-MICROSOFT-CDO-IMPORTANCE:1\n";
$stringData .= "CLASS:PUBLIC\n";
$stringData .= "END:VEVENT\n";
$stringData .= "END:VCALENDAR\n";
>
fwrite($fh, $stringData);
>
//CLOSE VCAL FILE
fclose($fh);
>
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "From: ".$email."\n";
$headers .= "To: ".$engineer_email."\n";
$headers .= "CC: ".$PM_email."\n";
$headers .= "Reply-To: ".$email."\n";
>
$headers .= "X-Priority: 1\n";
$headers .= "X-Mailer: DT Formmail".VERSION."\n";
$headers .= "Content-Type: multipart/mixed;\n\tboundary=\"".
$ob."\"\n";
>
//MESSAGE
$message .= "\n--".$ob."\n";
$message .= "Content-Type: multipart/alternative;\n\tboundary=\"".
$ib."\"\n\n";
$message .= "\n--".$ib."\n";
$message .= "Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n";
$message .= "Content-Transfer-Encoding: quoted-printable\n\n";
//WHAT
$message .= "<b>What: <br>";
$message .= "</b>$customer_name <br>";
$message .= "<br>";
//WHO
$message .= "<b>Who: <br>";
$message .= "</b>$individual_name <br>";
$message .= "$customer_phone <br>";
$message .= "$individual_email <br>";
$message .= "<br>";
//WHERE
$message .= "<b>Where: <br>";
$message .= "</b>$customer_street_address <br>";
$message .= "$customer_city, $customer_state <br>";
$message .= "<br>";
>
//WHEN
$message .= "<b>When: <br>";
$message .= "</b>$dayofweek <br>";
$message .= "$time <br>";
$message .= "$month $day, $year<br>";
$message .= "<br>";
>
//CONFIRMATION INFO
>
$message .= "<b>Checkpoints: <br>";
$message .= "</b>Was the activity confirmed with the customer?
$cust_confirmed <br>";
$message .= "</b>Is the activity in black on the schedule?
$ss_confirmed <br>";
>
if( $hardware_confirmed == "no") {
$message .= " <font color='#FF0000'>Is the required hardware
already onsite? $hardware_confirmed </font>
<br>";
}
else{
>
$message .= "</b>Is the required hardware already onsite?
$hardware_confirmed <br>";
}
>
>
$message .= "</b>Do we have any hours left in a T&M?
$hours_left <br>";
$message .= "</b>Do you assign the task to the engineer on his
timesheet? $time_sheet <br>";
$message .= "<br>";
>
//HERE WE ATTACH THE FILE
$fileatt = "dispatch.ics"; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = "dispatch.ics"; // Filename that will be used for the
file as the attachment
>
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
>
>
$data = chunk_split(base64_encode($data));
>
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}\n";
unset($data);
unset($file);
unset($fileatt);
unset($fileatt_type);
unset($fileatt_name);
>
$message .= "\n--".$ib."--\n";
>
$message .= "\n--".$ob."--\n";
>
>
$subject = "Scheduled activity for $customer_name ";
>
mail($recipient, $subject, $message, $headers);
>
>
?>
>
the PEAR Mail class.