|
Posted by robert on 09/28/07 11:46
<talthen.z-serwera.o2@nospam.pl> wrote in message
news:e3381q$3cv$1@nemesis.news.tpi.pl...
| Hello,
| I have an e-mail message in txt file. It contains fields
| Subject, To, From, Reply-To,Content-Type, X-Mailer and body.
| I want to send the file. I tried this way:
| mail('','','',$email_read_into_string);
| But I got- Warning: mail(): SMTP server response: 503.
|
| I would rather not parse the file to get fields- Subject, To and From as
| separate variables and then use them with mail().
| Can I send this file AS-IS?
if the file already contains to whom it should be sent, from whom, and the
subject, etc...and you're on a unix system, then just exec() the sendmail
command with the full path to the email text file. if you're on a windows
server and have write access to c:/inetpub/mailroot/pickup/ directory, then
just copy the file to that directory.
i hate php's mail function and don't like having to use a bunch of classes
to send formatted mail. i use the following which is fairly straight-forward
and takes the above approach for delivery:
(hth)
==================== code snippet
<?
class email
{
static function send(
$to ,
$from ,
$cc = '' ,
$bcc = '' ,
$subject ,
$text ,
$html = '' ,
$companyName = '' ,
$logo = null ,
$dropDirectory = '' ,
$exec = null
)
{
// prevent email injection hacks
$subject = preg_replace("/\nfrom\:.*?\n/i" , "", $subject);
$subject = preg_replace("/\nbcc\:.*?\n/i" , "", $subject);
$subject = preg_replace("/\ncc\:.*?\n/i" , "", $subject);
$text = preg_replace("/\nfrom\:.*?\n/i" , "", $text);
$text = preg_replace("/\nbcc\:.*?\n/i" , "", $text);
$text = preg_replace("/\ncc\:.*?\n/i" , "", $text);
$html = preg_replace("/\nfrom\:.*?\n/i" , "", $html);
$html = preg_replace("/\nbcc\:.*?\n/i" , "", $html);
$html = preg_replace("/\ncc\:.*?\n/i" , "", $html);
//
$messageHtml = $html;
$html = '
<html>
<style>
body
{
background-color : #FFFFFF;
color : black;
font-family : verdana, tahoma, arial, times new
roman, sans-serif;
font-size : 8pt;
padding : 2px;
text-align : left;
}
hr
{
background-color : lightsteelblue;
border : 0px;
color : lightsteelblue;
height : 1px;
}
table
{
border-collapse : collapse;
border-padding : 2px;
border-width : 0px;
border-spacing : 0px;
width : 700px;
}
td
{
background-color : #FFFFFF;
color : black;
font-family : verdana, tahoma, arial, "times new
roman", sans-serif;
font-size : 8pt;
margin : 5px;
padding-left : 5px;
padding-right : 5px;
spacing : 0px;
text-align : left;
vertical-align : top;
}
th
{
background-color : lavender;
color : black;
font-family : verdana, tahoma, arial, "times new
roman", sans-serif;
font-size : 8pt;
font-weight : bold;
margin : 5px;
text-align : left;
}
</style>
<body>
';
if (isset($logo))
{
$file = @fopen($logo, 'r');
$image = @fread($file, filesize($logo));
$image = @chunk_split(base64_encode($image));
@fclose($file);
unset($file);
$html .= '
<img alt="' . $companyName . '" border="0px"
src="cid:logo" style="float:right;">
<br>
<br>
<br>
<br clear="all">
';
}
if ($messageHtml == ''){ $messageHtml = $text; }
$html .= $messageHtml . '</body></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 . md5(uniqid(rand())) . '.eml';
$file = fopen($fileName, 'wb');
fwrite($file, $mail);
fclose($file);
unset($file);
if (!isset($exec)){ return $mail; }
exec($exec . $fileName);
return $mail;
}
}
?>
Navigation:
[Reply to this message]
|