Hi
i'd like to know if anyone has the code to be able to attach and email excel files using PHP. Basicallywhat i have is a process that opens an excel file on a directory on a windows machine and writes data to the file. What i need is something that emails the excel file as an attachement at the end of this process. I can get the email process working where it emails a message, but am having trouble emailing attachments. I've attached the current email function.
function send_email($to,$from,$repl
y,$subject
,$msg,$hos
t,$port,$d
omain,$pri
ority,$out
put)
{
if (!$host) { $host = ""; }
if (!$port) { $port = "25"; }
if (!$priority) { $priority = "1"; }
if (!$reply) { $reply = $from; }
$STATUS_OK = "2";
$STATUS_DATA_OK = "3";
$CRLF = "\r\n";
// Pull out the simple email if they are putting in 'name <email@domain.com>'
if (ereg("(([[:alnum:]]|\\-|\
\.)+@([^[:
space:]]*)
([[:alnum:
]-]))", $to, $reg_array))
{
$to = $reg_array[0];
}
if ($socket = fsockopen($host, $port))
{
list($status, $resp_msg) = each(read_response($socket
,$output))
;
if ($status == $STATUS_OK)
{
fputs($socket, "HELO" . $CRLF);
list($status, $resp_msg) = each(read_response($socket
,$output))
;
if ($status == $STATUS_OK)
{
fputs($socket, "MAIL FROM:" . $from . $CRLF);
list($status, $resp_msg) = each(read_response($socket
,$output))
;
if ($status == $STATUS_OK)
{
fputs($socket, "RCPT TO: " . $to . $CRLF);
list($status, $resp_msg) = each(read_response($socket
,$output))
;
if ($status == $STATUS_OK)
{
fputs($socket, "DATA" . $CRLF);
list($status, $resp_msg) = each(read_response($socket
,$output))
;
if ($status == $STATUS_DATA_OK)
{
$buffer = "From: $from$CRLF";
$buffer .= "To: $to$CRLF";
$buffer .= "Reply-To: $reply]$CRLF";
$buffer .= "Errors-To: $reply$CRLF";
$buffer .= "Bounce-To: $reply$CRLF";
$buffer .= "X-Priority: $priority$CRLF";
$buffer .= "X-Mailer: Zap Mailer w/PHP " . phpversion() . $CRLF;
$buffer .= "Subject: $subject$CRLF";
$buffer .= $CRLF;
$buffer .= $msg;
if ($output == "Y")
{
echo nl2br($buffer);
}
if (fputs($socket, $buffer . "$CRLF.$CRLF"))
{
list($status, $resp_msg) = each(read_response($socket
,$output))
;
if ($status == $STATUS_OK)
{
$send_success = true;
fputs($socket, "QUIT" . $CRLF);
}
}
}
}
}
}
}
fclose($socket);
}
}