472,982 Members | 2,372 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,982 software developers and data experts.

cannot add ics file attachment to email

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:Ad***********@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?
&nbsp;&nbsp; $cust_confirmed <br>";
$message .= "</b>Is the activity in black on the schedule?
&nbsp;&nbsp; $ss_confirmed <br>";

if( $hardware_confirmed == "no") {
$message .= " <font color='#FF0000'>Is the required hardware
already onsite? &nbsp;&nbsp; $hardware_confirmed </font>
<br>";
}
else{

$message .= "</b>Is the required hardware already onsite?
&nbsp;&nbsp; $hardware_confirmed <br>";
}
$message .= "</b>Do we have any hours left in a T&M?
&nbsp;&nbsp; $hours_left <br>";
$message .= "</b>Do you assign the task to the engineer on his
timesheet? &nbsp;&nbsp; $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);
?>















OUTPUT in email form:

What:
asd

Who:
asd
sad
asdasd

Where:
asd
sada, MA

When:
Monday
9am
February 2, 2008

Checkpoints:
Was the activity confirmed with the customer? yes
Is the activity in black on the schedule? yes
Is the required hardware already onsite? yes
Do we have any hours left in a T&M? yes
Do you assign the task to the engineer on his timesheet? yes

------=uterBoundary_000 Content-Type: application/octet-stream;
name=ispatch.ics" Content-Disposition: attachment;
filename=ispatch.ics" Content-Transfer-Encoding: base64
BEGIN:VCALENDAR PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//
EN VERSION:2.0 METHOD:PUBLISH BEGIN:VEVENT
ORGANIZER:MAILTO:Ad***********@exchange.org DTSTART:20060306T050000Z
DTEND:20060306T053000Z LOCATION:location TRANSP:OPAQUE SEQUENCE:0 UID:
040000008200E00074C5B7101A82E0080000000020DC2A1392 43C60100000000000000000000DEF81CB498E1594B90378312 C3D6551D
DTSTAMP:20060309T045649Z DESCRIPTION:FreeFormText. More FreeFormText.
SUMMARY:subject PRIORITY:5 X-MICROSOFT-CDO-IMPORTANCE:1 CLASS:PUBLIC
END:VEVENT END:VCALENDAR
Oct 23 '08 #1
2 4216
Erik Witkop wrote:
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:Ad***********@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?
&nbsp;&nbsp; $cust_confirmed <br>";
$message .= "</b>Is the activity in black on the schedule?
&nbsp;&nbsp; $ss_confirmed <br>";

if( $hardware_confirmed == "no") {
$message .= " <font color='#FF0000'>Is the required hardware
already onsite? &nbsp;&nbsp; $hardware_confirmed </font>
<br>";
}
else{

$message .= "</b>Is the required hardware already onsite?
&nbsp;&nbsp; $hardware_confirmed <br>";
}
$message .= "</b>Do we have any hours left in a T&M?
&nbsp;&nbsp; $hours_left <br>";
$message .= "</b>Do you assign the task to the engineer on his
timesheet? &nbsp;&nbsp; $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);
?>
[lots of newlines snipped]
>
OUTPUT in email form:

What:
asd

Who:
asd
sad
asdasd

Where:
asd
sada, MA

When:
Monday
9am
February 2, 2008

Checkpoints:
Was the activity confirmed with the customer? yes
Is the activity in black on the schedule? yes
Is the required hardware already onsite? yes
Do we have any hours left in a T&M? yes
Do you assign the task to the engineer on his timesheet? yes

------=uterBoundary_000 Content-Type: application/octet-stream;
name=ispatch.ics" Content-Disposition: attachment;
filename=ispatch.ics" Content-Transfer-Encoding: base64
BEGIN:VCALENDAR PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//
EN VERSION:2.0 METHOD:PUBLISH BEGIN:VEVENT
ORGANIZER:MAILTO:Ad***********@exchange.org DTSTART:20060306T050000Z
DTEND:20060306T053000Z LOCATION:location TRANSP:OPAQUE SEQUENCE:0 UID:
040000008200E00074C5B7101A82E0080000000020DC2A1392 43C60100000000000000000000DEF81CB498E1594B90378312 C3D6551D
DTSTAMP:20060309T045649Z DESCRIPTION:FreeFormText. More FreeFormText.
SUMMARY:subject PRIORITY:5 X-MICROSOFT-CDO-IMPORTANCE:1 CLASS:PUBLIC
END:VEVENT END:VCALENDAR
You'll probably find it easier to send attachments using PHP Mailer or
the PEAR Mail class.

PHP mailer: <URL:http://phpmailer.codeworxtech.com/>
PEAR Mail: <URL:http://pear.php.net/package/Mail>

--
Curtis
Oct 23 '08 #2
*** Erik Witkop escribió/wrote (Wed, 22 Oct 2008 18:49:38 -0700 (PDT)):
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.
[...]
OUTPUT in email form:

What:
asd

Who:
This is the body. Headers *do* matter; check them as well. Look at the
source code of the message in your favourite e-mail client and check that
the headers are right, the boundary markers are correct in both places, you
don't have empty lines before the body...
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor en cubitos: http://www.demogracia.com
--
Oct 23 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Paul Lamonby | last post by:
Hi, I am sending a file from the server as an email attachment. The file is being attached no problem and sending the email, but I get an error when I try to open it saying it is corrupt....
1
by: chuck amadi | last post by:
By the way list is there a better way than using the readlines() to > > >parse the mail data into a file , because Im using > > >email.message_from_file it returns > > >all the data i.e reads one...
4
by: moondaddy | last post by:
Using vb.net I need to download image files to the client browser where they can save to disk. Below is some sample code I'm using. when I run this the File Download window in the browser says: ...
5
by: Nick Z. | last post by:
When using SmtpClient and sending a message with an attached file using SendAsync(...), if I add File.Delete(pathToAttachedFile) in the SendCompleted event handler I get a file in use exception. Is...
4
by: Jonny | last post by:
Hello Group How do I open a Save File Dialog from an ASPX page behind a browse button? Any help would be fantastic!! I am using ASP.NET 1.1 using VB.NET as the coding language TIA
9
by: deepaks85 | last post by:
Dear Sir, I have created a simple request form which will be mailed to me. Now I want to attach files and send it through that request form. For this I am using the following script: ...
7
by: erikcw | last post by:
Hi all, I'm trying to extract zip file (containing an xml file) from an email so I can process it. But I'm running up against some brick walls. I've been googling and reading all afternoon, and...
1
by: nukephp | last post by:
Hello Guys would you know about php email with his attachment Working on linux platform................................................... The code as below: mail.php <?php //define the...
1
by: jerrygarciuh | last post by:
Hi folks, I have a PHP cron job that compiles a CSV from queries and emails it to some clients. I have a complaint that one client can see the indicating icon to say there is an attachment in...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.