Send Mail With multiple Attachment in PHP

<?php
error_reporting(E_ALL);
if(isset ($_POST[“send”]))
{
$upload_name=$_FILES[“upload”][“name”];
$upload_type=$_FILES[“upload”][“type”];
$upload_size=$_FILES[“upload”][“size”];
$upload_temp=$_FILES[“upload”][“tmp_name”];

$upload_name1=$_FILES[“upload1”][“name”];
$upload_type1=$_FILES[“upload1”][“type”];
$upload_size1=$_FILES[“upload1”][“size”];
$upload_temp1=$_FILES[“upload1”][“tmp_name”];

$message=$_POST[“msg”];
$body=”;
$subject = $_POST[“subject”];
$to=$_POST[“to”];
$separator = md5(time());
$eol = PHP_EOL;
$from=’admin@spoolster.com’;

$filename =’bankcopy.jpg’;
$filename1 =’nscibankcopy.jpg’;

if($message==””||$subject==””||$to==””)
{
echo ‘<font style=”font-family:Verdana, Arial; font-size:11px; color:#F3363F; font-weight:bold”>Please fill all fields</font>’;
}
else
{
$fp = fopen($upload_temp, “rb”);
$file = fread($fp, $upload_size);
$attachment = chunk_split(base64_encode($file));

$fp1 = fopen($upload_temp1, “rb”);
$file1 = fread($fp1, $upload_size1);
$attachment1 = chunk_split(base64_encode($file1));

$num = md5(time());

// main header
$headers = “From: “.$from.$eol;
$headers .= “MIME-Version: 1.0”.$eol;
$headers .= “Content-Type: multipart/mixed; boundary=\””.$separator.”\””;

$body = “–“.$separator.$eol;
$body .= “Content-Transfer-Encoding: 7bit”.$eol.$eol;
$body .= “This is a MIME encoded message.”.$eol;

// message
$body .= “–“.$separator.$eol;
$body .= “Content-Type: text/html; charset=\”iso-8859-1\””.$eol;
$body .= “Content-Transfer-Encoding: 8bit”.$eol.$eol;
$body .= $message.$eol;

// attachment
$body .= “–“.$separator.$eol;
$body .= “Content-Type: application/octet-stream; name=\””.$filename.”\””.$eol;
$body .= “Content-Transfer-Encoding: base64”.$eol;
$body .= “Content-Disposition: attachment”.$eol.$eol;
$body .= $attachment.$eol;

// attachment1
$body .= “–“.$separator.$eol;
$body .= “Content-Type: application/octet-stream; name=\””.$filename1.”\””.$eol;
$body .= “Content-Transfer-Encoding: base64”.$eol;
$body .= “Content-Disposition: attachment”.$eol.$eol;
$body .= $attachment1.$eol;
$body .= “–“.$separator.”–“;

// SEND MAIL
@mail($to, $subject, $body, $headers);
fclose($fp);

echo ‘<font style=”font-family:Verdana, Arial; font-size:11px; color:#333333; font-weight:bold”>Attachment has been sent Successfully.<br /></font>’;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Mail With Attachment</title>
</head>
<body>
<form id=”attach” name=”attach” method=”post” action=”<?php echo $_SERVER[“PHP_SELF”]; ?>” enctype=”multipart/form-data”>
<table>
<tr>
<td>To</td><td>:</td><td><input type=”text” name=”to” id=”to”></td>
</tr>
<tr>
<td>Subject</td><td>:</td><td><input type=”text” name=”subject” id=”subject”></td>
</tr>
<tr>
<td>Message</td><td>:</td><td><input type=”text” name=”msg” id=”msg”></td>
</tr>
<tr>
<td>Attachment<span class=”imp”>*</span></td><td>:</td><td><input type=”file” name=”upload” id=”upload”></td>
</tr>
<tr>
<td>Attachment<span class=”imp”>*</span></td><td>:</td><td><input type=”file” name=”upload1″ id=”upload1″></td>
</tr>
<tr>
<td></td><td></td><td><input type=”submit” value=”Submit” id=”send” name=”send”></td>
</tr>
</table>
</form>
</body>
</html>

Similar Posts

One Comment

  1. I just amazed with your coding techniques.
    Are you brilliant in PHP ? I didn’t know that much but i know only the basics.

Leave a Reply

Your email address will not be published. Required fields are marked *