|
Posted by windandwaves on 03/22/06 21:50
Jerry Stuckle wrote:
[....]
>
> So - what does this have to do with PHP, and why are you posting this
> in a PHP newsgroup?
Because ultimately it is a PHP application. The code is below. It may give
some people some ideas or help someone I thought (obviously more aimed at
beginners):
<?php
if($_POST["submit"]) {
//clean input
if(!$_POST["filename"]) {
$_POST["filename"] = "test";
}
$filename = alpha_numeric_make_one($_POST["filename"]).'.vbs';
$i = 0;
while(file_exists($filename)){
$i++;
$filename = $i.'_'.$filename;
}
if(!$_POST["html"]) {
$_POST["html"] = example_text();
}
$data = createvbscript($_POST["html"]);
$length = strlen($data);
if($length > (1024 * 4)) {
die("file is too large - sorry");
}
//create file
if (!$handle = fopen($filename, 'w+')) {
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, $data) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
fclose($handle);
//force download
@ob_end_clean();
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header('Content-Disposition: attachment; filename="'.$filename.'"' );
header("Content-Type: application/force-download");
// Length required for Internet Explorer
header("Content-Length: ".$length);
echo $data;
flush();
@ob_flush();
}
else {
$v = '<h1>create outlook stationery</h1>
<div id="explanation">
<p>This page creates a macro from an html file. The macro can be used by
people with Windows XP and Microsoft Office XP to write <i>fancy emails</i>.
This page may particularly useful for IT professionals with clients who
are interested in sending <i>html formatted</i> emails.</p>
<p>Please copy an html file below, keeping the following in mind:</p>
<ul>
<li>keep it simple</li>
<li>place all styles in elements (e.g. write <i><p style="margin:
10px;"></i>)</li>
<li>do not put styles in the header or the body tag, because these are
most likely to be removed by mail programs</li>
<li>make absolute references to external (image) files (e.g.
<i>http://www.mysite.com/logo.gif</i> rather than <i>logo.gif</i>)</li>
<li><a href="http://validator.w3.org">validate</a> your file before
submitting it</li>
<li>do not use lightly coloured fonts (e.g. white) or dark backgrounds
(e.g. black), because the person may reply without the background colour or
without the font colour. </li>
<li><b>only works for people with Windows XP and MS Office XP</b> -
please let me know if you need a different format and I will endeavour to
create it.</li>
<li>to see an example, just enter a filename and leave the html field
blank.</li>
<li>the maximum file size for this example is 2Kb.</li>
</ul>
</div>
<h1>enter details below</h1>
<div id="former">
<form method="post" action="index.php">
<p>
html document: <br />
<textarea cols="50" rows="20" name="html"></textarea>
<br />file name:<input name="filename" />
<br /><input type="submit" name="submit" value="create VB Script macro
for fancy formatted email" id="submit" />
</p>
</form>
</div>
<h1>example html document</h1>
<div id="sampler">
<pre>'.htmlentities(example_text()).'</pre>
</div>
';
}
$html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<title>create outlook stationery</title>
<link rel="icon" href="http://www.sunnysideup.co.nz/i/favicon.ico"
type="image/ico" />
<link rel="shortcut icon"
href="http://www.sunnysideup.co.nz/i/favicon.ico" />
<link href="s/s.css" rel="stylesheet" type="text/css" />
<meta name="keywords" content="create outlook stationery" />
<meta name="description" content="create outlook stationery" />
</head>
<body>
<div id="title">
<img src="i/logo.gif" alt="Sunny Side Up - Stationery it" title="Sunny
Side Up - Stationery it" width="720" height="140" />
</div>
'.$v.'
</body>
</html>';
echo $html;
function createvbscript($s) {
$s = str_replace('"', '" & chr(34) & "', $s);
$s = str_replace("\r", ' ', $s);
$s = str_replace("\n", ' ', $s);
$s = str_replace(' ', ' ', $s);
$v = '
Dim theApp
Set theApp = WScript.CreateObject("Outlook.Application")
CreateHTMLMail(theApp)
Public Sub CreateHTMLMail(olapp)
Dim objMail
Set objMail = olApp.CreateItem(olMailItem)
With objMail
.BodyFormat = 2
.HTMLBody = "'.$s.'"
.Display
End With
End Sub';
return $v;
}
function alpha_numeric_make_one ($s) {
//replaces all non alpha-numeric entries
if($s) {
$s = eregi_replace("[^[:alnum:]]", " ", $s);
$s = trim(eregi_replace(" +", "", $s)); //removes excess spaces
return $s;
}
return false;
}
function example_text() {
return '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<title>sexy message from me</title>
</head>
<body style="background-color: #D4D0C8; padding: 0px; margin: 0px auto 0px
auto;">
<div id="container" style="background-color: #D4D0C8; padding: 0px;
margin-left: auto; margin-right: auto;" align="center">
<div id="main" style="background-color: white; margin: 0px auto 0px
auto; width: 380px; padding: 20px;" align="Center">
<p style="padding: 0px; margin: 0px; text-align: center; color:
#333333; ">
<br>
double-click to edit
<br>
</p>
</div>
</div>
</body>
</html>';
}
?>
Navigation:
[Reply to this message]
|