hi everyone… now i am sending an email with 4 attachments through PHP
when i press send mail, the mail will b e snet with attachments… and everything is working well
now i want to make save as draft button to save the mail and it’s attachment into database and try to send it later.
i uploaded the files attached into server and tried to send the mail with attachement
but when i send it , it delivered without the attachments
how i can send the saved attachments to e-mails? noted that it is uploaded into server and saved into database
my code is:
<?
$from = EMAIL_SENDER;
$to = $_POST['to'];
$subject = htmlspecialchars($subject, ENT_QUOTES);
$headers = "From: $from";
if(($cc!='')||(isset($cc)))
{
$headers .= "Cc: $cc";
}
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment
$headers .= "\
MIME-Version: 1.0\
" .
"Content-Type: multipart/mixed;\
" .
" boundary=\\"{$mime_boundary}\\"";
$message='
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style>
body {
font-family: Tahoma;
font-size: 13px;
text-align: justify;
width: auto;
margin-right: 0px;
margin-left: 0px;
margin-top: 10px;
margin-bottom: 10px;
line-height: 17px;
}
.title1 {
font-size: 14px;
font-weight: normal;
color: #000000;
padding-top: 10px;
padding-bottom: 10px;
font-family: Arial, Helvetica, sans-serif;
}
.em_texti {
color: #000000;
margin-top: 20px;
margin-bottom: 20px;
border: 2px groove #CCCCCC;
}
</style>
</head>
<body>
<table align="center" width="780" cellpadding="10">
<tr>
<td>
<br><br>
<div class="title1" align="left">Dear ' .$name . ',</div>
<br>' . stripslashes($info_text). '
</td>
</tr>
</table>
</body>
</html>';
$message = "This is a multi-part message in MIME format.\
\
" .
"--{$mime_boundary}\
" .
"Content-type: text/html; charset=windows-1256\\r\
" .
"Content-Transfer-Encoding: 7bit\
\
" .
$message . "\
\
";
// Base64 encode the file data
// Obtain file upload vars
$fileatt = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];
$fileatt2 = $_FILES['fileatt2']['tmp_name'];
$fileatt2_type = $_FILES['fileatt2']['type'];
$fileatt2_name = $_FILES['fileatt2']['name'];
$fileatt3 = $_FILES['fileatt3']['tmp_name'];
$fileatt3_type = $_FILES['fileatt3']['type'];
$fileatt3_name = $_FILES['fileatt3']['name'];
$fileatt4 = $_FILES['fileatt4']['tmp_name'];
$fileatt4_type = $_FILES['fileatt4']['type'];
$fileatt4_name = $_FILES['fileatt4']['name'];
if (is_uploaded_file($fileatt)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$data = chunk_split(base64_encode($data));
$message .= "--{$mime_boundary}\
" .
"Content-Type: {$fileatt_type};\
" .
" name=\\"{$fileatt_name}\\"\
" .
//"Content-Disposition: attachment;\
" .
//" filename=\\"{$logoatt_name}\\"\
" .
"Content-Transfer-Encoding: base64\
\
" .
$data. "\
\
";
}
if (is_uploaded_file($fileatt2)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt2,'rb');
$data = fread($file,filesize($fileatt2));
fclose($file);
$data = chunk_split(base64_encode($data));
$message .= "--{$mime_boundary}\
" .
"Content-Type: {$fileatt2_type};\
" .
" name=\\"{$fileatt2_name}\\"\
" .
//"Content-Disposition: attachment;\
" .
//" filename=\\"{$logoatt_name}\\"\
" .
"Content-Transfer-Encoding: base64\
\
" .
$data. "\
\
";
}
if (is_uploaded_file($fileatt3)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt3,'rb');
$data = fread($file,filesize($fileatt3));
fclose($file);
$data = chunk_split(base64_encode($data));
$message .= "--{$mime_boundary}\
" .
"Content-Type: {$fileatt3_type};\
" .
" name=\\"{$fileatt3_name}\\"\
" .
//"Content-Disposition: attachment;\
" .
//" filename=\\"{$logoatt_name}\\"\
" .
"Content-Transfer-Encoding: base64\
\
" .
$data. "\
\
";
}
if (is_uploaded_file($fileatt4)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt4,'rb');
$data = fread($file,filesize($fileatt4));
fclose($file);
$data = chunk_split(base64_encode($data));
$message .= "--{$mime_boundary}\
" .
"Content-Type: {$fileatt4_type};\
" .
" name=\\"{$fileatt4_name}\\"\
" .
//"Content-Disposition: attachment;\
" .
//" filename=\\"{$logoatt_name}\\"\
" .
"Content-Transfer-Encoding: base64\
\
" .
$data. "\
\
";
}
$ok = @mail($to, $subject, $message, $headers);
?>