I was just wondering and searching the internet. Is it possible to create an appointment via mail and send it as an attachement so you can save it on your calenders client.
And is it possible within PHP? If so, can anyone give me an example or tutorial?
Thanks in advance
header("Content-Type: text/Calendar");
header("Content-Disposition: inline; filename=calendar.ics");
echo "BEGIN:VCALENDAR\n";
echo "VERSION:2.0\n";
echo "PRODID:-//Foobar Corporation//NONSGML Foobar//EN\n";
echo "METHOD:REQUEST\n"; // requied by Outlook
echo "BEGIN:VEVENT\n";
echo "UID:".date('Ymd').'T'.date('His')."-".rand()."-example.com\n"; // required by Outlok
echo "DTSTAMP:".date('Ymd').'T'.date('His')."\n"; // required by Outlook
echo "DTSTART:20080413T000000\n";
echo "SUMMARY:TEST\n";
echo "DESCRIPTION: this is just a test\n";
echo "END:VEVENT\n";
echo "END:VCALENDAR\n";
http://www.terminally-incoherent.com/blog/2008/04/14/generate-outlook-calendar-events-with-php-and-icalendar/
You can replace the info with get variables to make dynamic links.
Related
I'm making a form (form.php) for user to insert data, after user finish inserting data, form action will jump to formGenerateXLS.php (using POST method) for generate user data to XSL file. In the bottom of formGenerateXLS.php I put a javascript code to jump to dashboard (home.php) but it fail. The Excel file successfully generate but javascript code not working. How to work with that?
if(isset($_POST['issue_time'])){
$product_desc = $_POST['product'];
$filename_excel = date("Ymd_")."$product_desc";
header("Content-type: application/vnd-ms-excel");
header("Content-Disposition: attachment; filename=$filename_excel.xls");
echo "<table border='1'>";
echo "<tr>";
echo "<th colspan='3' bgcolor='#1bf3b3'>New Ticket Request</th>";
echo "</tr>";
echo "<tr>";
echo "<td>Name</td>";
echo "<td></td>";
echo "<td>User</td>";
echo "</tr>";
echo "</table>"
}
echo "<script>window.location='home.php'</script>";
Because echo does not execute the command, but simply writes it to the file.
In order to reposition a php file, use the header () function, for example header ('location: home.php');.
I need to be able to create an archive(zip) file with password protection using PHP. I am using Laravel 5.4 and PHP 7.1 version. I looked at this link here for ZipArchive class documentation in PHP. I also looked at here for setPassword function. But appears that creation of password protected archives is not supported. It will be a massive surprise for me if it is not possible to create password protected archive in a mature programming language such as PHP 7.1.
So I guess I must be missing something. Can someone point me to the right direction? E.g. a sample example or open source third party library or extension to achieve this will be greatly appreciated.
Easy peasy lemon squeezy (no).
Yes, creation of password protected archives is not supported (they will be created simply as non-protected archives, as you just described).
But, still it can be used to extract password protected archives.
Returning to the problem.
You always can just
<?php echo system('zip -P pass file.zip file.txt'); ?>
(this will work both on Windows and our beloved Linux)
But, if it not fits into your requirements, let's continue.
I would suggest you to use DotNetZip (Windows only), you will exactly dynamically generate AES-encrypted zip archives from PHP.
<?php
// origin: https://stackoverflow.com/a/670804/3684575
try
{
$fname = "zip-generated-from-php-" . date('Y-m-d-His') . ".zip";
$zipOutput = "c:\\temp\\" . $fname;
$zipfact = new COM("Ionic.Zip.ZipFile");
$zip->Name = $zipOutput;
$dirToZip= "c:\\temp\\psh";
# Encryption: 3 => 256-bit AES.
# 2 => 128-bit AES.
# 1 => PKZIP (Weak).
# 0 => None
$zip->Encryption = 3;
$zip->Password = "AES-Encryption-Is-Secure";
$zip->AddDirectory($dirToZip);
$zip->Save();
$zip->Dispose();
if (file_exists($zipOutput))
{
header('Cache-Control: no-cache, must-revalidate');
header('Content-Type: application/x-zip');
header('Content-Disposition: attachment; filename=' . $fname);
header('Content-Length: ' . filesize($zipOutput));
readfile($zipOutput);
unlink($zipOutput);
}
else
{
echo '<html>';
echo ' <head>';
echo ' <title>Calling DotNetZip from PHP through COM</title>';
echo ' <link rel="stylesheet" href="basic.css"/>';
echo ' </head>';
echo '<body>';
echo '<h2>Whoops!</h2>' . "<br/>\n";
echo '<p>The file was not successfully generated.</p>';
echo '</body>';
echo '</html>';
}
}
catch (Exception $e)
{
echo '<html>';
echo ' <head>';
echo ' <title>Calling DotNetZip from PHP through COM</title>';
echo ' <link rel="stylesheet" href="basic.css"/>';
echo ' </head>';
echo '<body>';
echo '<h2>Whoops!</h2>' . "<br/>\n";
echo '<p>The file was not successfully generated.</p>';
echo '<p>Caught exception: ', $e->getMessage(), '</p>', "\n";
echo '<pre>';
echo $e->getTraceAsString(), "\n";
echo '</pre>';
echo '</body>';
echo '</html>';
}
?>
But still, this is very dirty solution and more of that, not works on Linux.
So, although PHP is a mature language, there is no adequate method (excluding custom extension or something like that) to achieve such a simple task with pure PHP.
What you also can do, is to wait until PHP 7.2 will be available for production (cuz ZipArchive::setEncryptionName is implemented (thanks to Pierre and Remi)).
But, until then you also can try to port php_zip >= 1.14.0 to PHP < 7.2, but there is currently no compiled binaries available, so you have to compile it yourself and try if it is possible at all (I believe it is).
p.s. I would try it, but have no VS2015+ on my PC right now.
My website generates a unique key(password) for each account to login. It is important, confidential, and unrecoverable. So how do I make it downloadable as txt for everyone.
This the code:
echo '<h2>';
print "Welcome $username to your dashboard<br>";
}
echo "</h2>";
echo "<p>";
$sec_value = 'usqi3289';
$rdecrypted_text = mcrypt_ecb(MCRYPT_DES, $sec_value, $userkey, MCRYPT_DECRYPT);
echo "<div class='button special'>Your Userkey: <font color='black'>$rdecrypted_text</font></div>";
?>
<br><p align="center">Please save your Userkey first,This is confidential and unrecoverable, because we don't hold any passwords. </p>
Mainly this one:
"<div class='button special'>Your Userkey: <font color='black'>$rdecrypted_text</font></div>"; ?>
I want a button below that so people click on it and it downloads a txt file containing this userkey.
You can put this code in a PHP file, e.g. userkeydl.php:
<?php
header("Content-type: text/plain");
header("Content-Disposition: attachment; filename = userkey.txt");
print "Your Userkey is: \n";
print $rdecrypted_text;
print "\nPlease note that this is confidential and unrecoverable.";
?>
1st, I know mysql_ is outdated and I should use mysqli (unfortunatly, I inherited this system and its way too much work to change it over at the present time)
The problem I have is when I execute the code, I am getting random blank emails. This system loops through a list of stores in a database and lists the information in a table for the store managers. It doesnt really matter what information is being presented. Does anyone see anything right off hand that micht cause this problem?
while($store = mysql_fetch_array($result_store)){
#Updates the Report Date for each store in the Loop
$report_date = "UPDATE ActiveStores SET Report_Date = '$Today' WHERE StoreNumber = $store[StoreNumber]";
if (!mysql_query($report_date, $con)){
die('Error: ' . mysql_error());
}
#Selects data from ActiveStores for the current store in the loop
$result2 = mysql_query("SELECT * FROM ActiveStores WHERE StoreNumber = '$store[StoreNumber]' ORDER BY StoreNumber");
#Loops through the currently selected store and Creates an Array of the data
while ($row = mysql_fetch_array($result2)) {
#Sets Store Variable
$Store = $row['StoreNumber'];
echo '<table width="1110"><table width="1102"><tr>';
# To Email Address
#$emailaddress = '******#*****.com';
# Message Subject
$emailsubject= 'Testing Report - Store: ' . $Store;
#Turn on Output buffer for email
ob_start();
#Heading for Report
echo '<h2 class="blktext">Walgreens Weekly Report - ' . $Today . '<br /></h2>';
echo '<h2>Insurance Orders:</h2>';
#Cancelled Orders for the store this week
$result_cash_canceled = mysql_query("SELECT * FROM Orders WHERE StoreNumber = '$Store' AND Cancel = 'checked' AND Order_Type = 'Cash' AND Cancel_Date > '$Sevendaysback'");
$tot_ord_ins_prt = mysql_num_rows($result_cash_canceled);
if ($tot_ord_ins_prt !== 0){
echo '<h4 class="blktext">Cancelled Orders for the store this week</h4><span class="blktext">';
echo '<p><i>Fitter Action: Fitter to contact client to notify of cancelled order, if not initialed by client.</i></p>';
echo "<table border='4' class='rpttbl' frame='hsides' rules='rows' width='1400'>";
echo '<tr><th>Store #</th><th>Order #</th><th>Customer</th><th>Phone #</th><th>Cancel Date</th width="150"><th>Reason for Cancellation</th><th width = "150">Patient Notified<th></tr>';
while($row_cash_canceled = mysql_fetch_array($result_cash_canceled)){
echo "<tr>";
echo "<td align='center'>" . $row_cash_canceled['StoreNumber'] . "</td>";
echo "<td align='center'>" . $row_cash_canceled['Order_ID'] . "</td>";
echo "<td align='center'>" . $row_cash_canceled['Cust_First_Name'] . " " . $row_bo['Cust_Last_Name'] . "</td>";
echo "<td align='center'>" . $row_cash_canceled['Cust_Phone'] . "</td>";
echo "<td align='center'>" . $row_cash_canceled['Cancel_Date'] . "</td>";
echo "<td align='center'> </td>";
echo "<td align='left'>( ) Called: Patient Cancelled notified<br />( ) Called: LVM for Patient</td>";
echo "</tr>";
}
echo "</table>";
echo "Total: " . $tot_ord_ins_prt;
echo'</span>';
}
#Message at bottom of email
echo '<br /><br /><br /><br /><p>Thank you for your prompt attention to this report.</p>';
echo '<p>If this report is blank in all the above sections, this means, at this point, we are not showing any active orders within our system.<br />';
echo 'If you feel this is in error, please contact our Customer Care team at: <strong>(***) ***-8125</strong></p>';
echo '<p>Please update this form with the appropriate action taken by patient, and fax back to: (866) 8**-**** OR email to: ******#*****.com</p>';
echo '<p>Fitter Name: ________________________________________</p>';
echo '<p>Comments: _______________________________________________________________<br />';
echo '_________________________________________________________________________</p>';
echo '<p>The information contained in this email, together with any attachments, is intended only for the use of the individual or entity<br /> to which it is addressed. It may contain information that is confidential and prohibited from disclosure. If you are not the intended <br />';
echo 'recipient, you are hereby notified that any dissemination, or copying, of this message or any attachment is strictly prohibited.</br> If you have received this message<br /> in error, please notify the original sender immediately by phone or by return email, </br>';
echo 'and delete this email, along with any attachments. <br />Receipt by anyone other than the intended recipient is not</br> a waiver of any privileged information. </p>';
}
$body=ob_get_contents();
ob_end_clean();
#$body = "** It is Imperative that you respond to this email. When you receive this please print it out, sign your name and store number and fax the form to ***-***-1161**<br /><br /><br />";
#$body .= "Name: <br /><br />Store #:";
$headers = 'From: Visual Footcare Technologies *****#****.com'.$eol;
$headers .= 'Reply-To: Visual Footcare Technologies *****#*****.com'.$eol;
$headers .= 'Return-Path: Visual Footcare Technologies <mcooper#visualfootcare.com>'.$eol; // these two to set reply address
#$headers .= 'Cc: ******#*****.com'.$eol;
$headers .= "Message-ID:<".$now." TheSystem#".$_SERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters
$mime_boundary=md5(time());
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
$msg = "";
$msg .= "Content-Type: multipart/alternative".$eol;
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= $body.$eol.$eol;
$msg .= "--".$mime_boundary."--".$eol.$eol; // finish with two eol's for better security. see Injection.
then a standard mail(......) code to send the email and then ending the loop.
hope that makes sense.
try changing this
if ($tot_ord_ins_prt !== 0)
to
if ($tot_ord_ins_prt !== false)
MIME header blocks must be terminated by a blank line, even when used in a multi-part section. I don't know what you mean by "random", but I suspect that "blank emails" could be the result of your message body being interpreted as invalid MIME headers.
Insert a blank line between the last MIME header and your message body:
$msg .= $eol.$body.$eol.$eol;
If this doesn't help, you should probably show that "standard" mail line you mentioned. Since it's the one that actually sends the email, I'm surprised you didn't include it. You included a whole lot of other code. It would be good to see what you do with the two strings, $headers and $msg.
Anyone knows how i can add a anchor to a web page that will force an Outlook Calendar file download? I need the file to open with outlook and the calendar info to be added to the user's calendar.
How can I create the MS outlook calendar files? Is there a standard/documented way I can create these calendar files using a script/automated way? (the script will be written in php)
thanks -
<?php
//This is the most important coding.
header("Content-Type: text/Calendar");
header("Content-Disposition: inline; filename=filename.ics");
echo "BEGIN:VCALENDAR\n";
echo "PRODID:-//Microsoft Corporation//Outlook 12.0 MIMEDIR//EN\n";
echo "VERSION:2.0\n";
echo "METHOD:PUBLISH\n";
echo "X-MS-OLK-FORCEINSPECTOROPEN:TRUE\n";
echo "BEGIN:VEVENT\n";
echo "CLASS:PUBLIC\n";
echo "CREATED:20091109T101015Z\n";
echo "DESCRIPTION:How 2 Guru Event\\n\\n\\nEvent Page\\n\\nhttp://www.myhow2guru.com\n";
echo "DTEND:20091208T040000Z\n";
echo "DTSTAMP:20091109T093305Z\n";
echo "DTSTART:20091208T003000Z\n";
echo "LAST-MODIFIED:20091109T101015Z\n";
echo "LOCATION:Anywhere have internet\n";
echo "PRIORITY:5\n";
echo "SEQUENCE:0\n";
echo "SUMMARY;LANGUAGE=en-us:How2Guru Event\n";
echo "TRANSP:OPAQUE\n";
echo "UID:040000008200E00074C5B7101A82E008000000008062306C6261CA01000000000000000\n";
echo "X-MICROSOFT-CDO-BUSYSTATUS:BUSY\n";
echo "X-MICROSOFT-CDO-IMPORTANCE:1\n";
echo "X-MICROSOFT-DISALLOW-COUNTER:FALSE\n";
echo "X-MS-OLK-ALLOWEXTERNCHECK:TRUE\n";
echo "X-MS-OLK-AUTOFILLLOCATION:FALSE\n";
echo "X-MS-OLK-CONFTYPE:0\n";
//Here is to set the reminder for the event.
echo "BEGIN:VALARM\n";
echo "TRIGGER:-PT1440M\n";
echo "ACTION:DISPLAY\n";
echo "DESCRIPTION:Reminder\n";
echo "END:VALARM\n";
echo "END:VEVENT\n";
echo "END:VCALENDAR\n";
?>
Just in case someone needs it in PHP. I was searching found this.
Create an outlook .ics file
See here for more information. The example is in .NET, but it is simply writing output, so very easy to translate to PHP.