Taka
Mon 19 March 2007, 04:14 pm GMT +0100
Quote
<?php
$toemail = $_POST['toemail'];
$fromemail = "testing@gmail.com";
$subject = $_POST['subject'];
$attachments = $HTTP_POST_FILES['attach'];
$message = $_POST['message'];
if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $toemail)) {
echo "<h4>Invalid email address</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
} elseif ($subject == "") {
echo "<h4>No subject</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
}
else{
function send_mail($toemail, $fromemail, $subject, $message, $attachments=flase)
{
$eol="\r\n";
$mime_boundary=md5(time());
$headers .= 'From: Taka<'.$fromemail.'>'.$eol;
$headers .= 'Reply-To: Taka<'.$fromemail.'>'.$eol;
$headers .= 'Return-Path: Taka<'.$fromemail.'>'.$eol;
$headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol;
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
$msg="";
if ($attachments !== false)
{
for($i=0; $i < count($attachments); $i++)
{
if (is_file($attachments[$i]["file"]))
{
$file_name = substr($attachments[$i]["file"], (strrpos($attachments[$i]["file"], "/")+1));
$handle=fopen($attachments[$i]["file"], 'rb');
$f_contents=fread($handle, filesize($attachments[$i]["file"]));
$f_contents=chunk_split(base64_encode($f_contents)); //Encode The Data For Transition using base64_encode();
fclose($handle);
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: ".$attachments[$i]["content_type"]."; name=\"".$file_name."\"".$eol;
$msg .= "Content-Transfer-Encoding: base64".$eol;
$msg .= "Content-Disposition: attachment; filename=\"".$file_name."\"".$eol.$eol; // !! This line needs TWO end of lines !! IMPORTANT !!
$msg .= $f_contents.$eol.$eol;
}
}
# Setup for text OR html
$msg .= "Content-Type: multipart/alternative".$eol;
# HTML Version
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= $message.$eol.$eol;
$msg .= "--".$mime_boundary."--".$eol.$eol;
ini_set(send_mail,$fromemail); // the INI lines are to force the From Address to be used !
mail($toemail, $subject, $msg, $headers);
ini_restore(send_mail);
echo "mail sent successfully";
}
}
}
send_mail($toemail, $fromemail, $subject, $attachments, $message);
?>
My input fields form names are:
To: ($toemail)
Subject: ($subject)
File Attachment ($attach)
Message ($message)
what's wrong with my script?Mr. Olaf?
When i received...it shows nothing in attachment with 0kb capacity
besides that...my message content also cannot received.Anything wrong of this scripts?
Thanks!!