You are here: Re: Need a simple database for name and email only « All PHP « IT news, forums, messages
Re: Need a simple database for name and email only

Posted by Steve on 03/24/07 17:18

"Webmaster of campbarbee.com" <@> wrote in message
news:UYudncfMqq3d0pjbnZ2dnUVZ_rWnnZ2d@comcast.com...
| >
| > csv and xls are text files. xls is a stylization for xml (which is
probably
| > what you meant). as it is, there are hundreds of examples on the
net...and,
| > this sounds a lot like a spamming enterprise.
|
|
|
| Hi Steve,
|
| Actually, it's for the annual group of kids at a Christian Church Camp
| who want to leave their email addresses for their friends.
|
| Go to www.campbarbee.com and click on the "Email Addresses" link and
| you'll see the CGI script that I want to replace with something a
| little more modern before my hosting service does away with their
| support for CGI sometime this summer.
|
| Any suggestions about where I can find a few of those hundreds of
| examples on the net that you wrote about? I would really like to see a
| few of them before our host dumps CGI support.

well, make it hundreds of examples plus one. rather than give a lecture on
how to google and given that you refrained quite nicely from firing back
with 'fuck off', here's what i've been using for years. i'm sure your love
of spammers has fostered your understanding of my reluctance to further the
cause.

here are some supporting files (assumes php 5)...you'll need to clean up the
text-wrapping, and i typed the example at the bottom without testing...you
may get syntax errors from php if i forgot something.

==== cvs.class.php

<?
class csv
{
private $_records = array();

private function __clone(){}

function __construct($path, $delimiter = '", "', $lineTerminator = "\n",
$firstRowHeader = true)
{
$fileHandle = fopen($path, 'r');
$records = explode($lineTerminator, fread($fileHandle,
filesize($path)));
fclose($fileHandle);
$recordCount = count($records);
for ($i = 0; $i < $recordCount; $i++)
{
$record = substr($records[$i], 1, -1);
$records[$i] = explode($delimiter, $record);
}
$columns = array();
$columnCount = count($records[0]);
for ($i = 0; $i < $columnCount; $i++)
{
$columns[$i] = $firstRowHeader ? strtoupper($records[0][$i]) : $i;
}
for ($record = ($firstRowHeader ? 1 : 0); $record < $recordCount;
$record++)
{
for ($column = 0; $column < $columnCount; $column++)
{
$this->_records[$record][$columns[$column]] =
$records[$record][$column];
}
}
}

function records(){ return $this->_records; }
}
?>

====== email.class.php

<?
class email
{
static function send(
$to ,
$from ,
$cc = '' ,
$bcc = '' ,
$subject ,
$text = '' ,
$html = '' ,
$companyName = '' ,
$logo = null ,
$dropDirectory = '' ,
$exec = '' ,
$execOptions = ''
)
{
$messageHtml = $html;
$html = '
<html>
<style>
body
{
background-color : white;
color : black;
font-family : verdana, tahoma, arial, times new
roman, sans-serif;
font-size : 8pt;
margin : 0px;
text-align : left;
}
</style>
<body>
';
if (isset($logo))
{
$image = file_get_contents($logo);
$image = chunk_split(base64_encode($image));
$html .= '
<img alt="' . $companyName . '" border="0px"
src="cid:logo" style="float:right;">
<br>
<br>
<br>
<br clear="all">
';
}
if ($messageHtml == ''){ $messageHtml = '<html><body>' . $text; }
$html .= $messageHtml . '</body></html>';
if ($text == ''){ $text = $html; }
$boundry = '----=' . md5(uniqid(rand()));
$related = '----=' . md5(uniqid(rand()));
$mail = "MIME-Version: 1.0\r\n";
$mail .= "TO: " . $to . "\r\n";
$mail .= "FROM: " . $from . "\r\n";
$mail .= "CC: " . $cc . "\r\n";
$mail .= "BCC: " . $bcc . "\r\n";
$mail .= "Subject: " . $subject . "\r\n";
$mail .= "Content-Type: multipart/related;
boundary=\"$related\"\r\n\r\n\r\n";
$mail .= "--$related\r\n";
$mail .= "Content-Type: multipart/alternative;
boundary=\"$boundry\"\r\n\r\n\r\n";
$mail .= "--$boundry\r\n";
$mail .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$mail .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
$mail .= $text . "\r\n\r\n";
$mail .= "--$boundry\r\n";
$mail .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n";
$mail .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
$mail .= $html . "\r\n\r\n";
$mail .= "--$boundry--\r\n\r\n";
$mail .= "--$related\r\n";
$mail .= "Content-Type: image/jpeg\r\n";
$mail .= "Content-ID: logo\r\n";
$mail .= "Content-Disposition: attachment;
filename=\"logo.jpg\"\r\n";
$mail .= "Content-Transfer-Encoding: base64\r\n\r\n";
$mail .= $image . "\r\n\r\n";
$mail .= "--$related--\r\n\r\n";
$mail .= "-- End --\r\n";
$fileName = $dropDirectory . strtoupper(md5(uniqid(rand()))) . '.eml';
file_put_contents($fileName, $mail);
if (!$exec){ return $mail; }
exec($exec . $fileName . $execOptions);
@unlink($fileName);
return $mail;
}
}
?>

====== now to put it all together ...
====== assumes window env using iis smtp.
====== assumes 1st row has field names and that
====== one of them is named 'email'. otherwise
====== access the address based on it's ordinal
====== field position, i.e. $records[3];

<?
require_once 'csv.class.php;
require_once 'email.class.php';

$admin = 'some.one@example.com';
$company = 'some enterprise';
$dropDirectory = 'c:/inetpub/mailroot/pickup/'; // php needs write perm.
$exec = ''; // *nix (using sendmail) - '/usr/sbin/sendmail -ti < '
$fileDb = 'data/some.csv';
$logo = 'images/my.email.logo.jpg';
$message = 'hello world';
$options = ''; // *nix - any additional args for sendmail
$subject = 'test email';

$csv = new csv($fileDb);

foreach ($csv->records() as $record)
{
email::send(
$record['EMAIL'] ,
$admin ,
'' ,
'' ,
$subject ,
$message ,
'' ,
$company ,
$logo ,
$dropDirectory ,
$exec ,
$options
);
}
?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация