473,385 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 4259
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.