JAY BHARAT, software enginer, php programmers, software engineer, jay bharat ,9844542127

 
»
S
I
D
E
B
A
R
«
file attachment send mail code in php
September 25th, 2009 by admin

For trial click here

Below php code:

<?php
/*print_r($_POST);
print_r($_FILES);
exit;*/
if(isset($_POST['txt_firstname']))
{
$firstname=$_POST['txt_firstname'];
$lastname=$_POST['txt_lastname'];
$email=$_POST['txt_email'];
if($firstname== '' || $lastname== '' || $email=='')
{
echo "You should Enter the required fields";
}
elseif($_FILES['txt_resume']['name']=="")
{
$toaddress = $email;
$subject = "Your homework submission!";
$firstname=$_POST['txt_firstname'];
$lastname=$_POST['txt_lastname'];
$email=$_POST['txt_email'];
$message=$_POST['message'];
// message
$message = "
<html>
<head>
<title>Sarika</title>
</head>
<body>
<table>
<tr>
<td>Dear $firstname</td>
</tr>
<tr>
<td>Your details,</td>
</tr>
<tr>
<td><b>First Name:<b> $firstname</td>
</tr>
<tr>
<td><be>Last Name:<b> $lastname</td>
</tr>
<tr>
<td><be>Message:<b>". nl2br($message)."</td>
</tr>
<tr>
<td>Email: $email</td>
</tr>
<tr>
<td>Regards</td>
</tr>
<tr>
<td>ADMIN jaybharatjay@gmail.com</td>
</tr>
</table>
</body>
</html>
";
$headersĀ  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "To: $row[emails] <$row[emails]>\r\n";
$headers .= "From: tutorial bharatbaba.com Mailing System <$email>\r\n";
$headers .= "Cc: jaybharatjay@yahoo.co.in\r\n";
$headers .= "Bcc: jaybharatjay@gmail.com\r\n";
$success = @mail($toaddress,$subject,$message,$headers)or
die('<br><strong>Unfortunately, your message could not be delivered.<br>Please Check Localhost or Website</strong>');
if ($success)
{
// Redirect to thank you page.
Header("Location: thanks.php");
}
}
else
{
//Attach mail sending start
$uploaddir = 'attachmentsTemp/';
$uploadfile = $uploaddir . basename($_FILES['txt_resume']['name']);
if (move_uploaded_file($_FILES['txt_resume']['tmp_name'], $uploadfile))
{
$fileatt = $uploadfile;
$fileatt_type = "application/octet-stream";
$fileatt_name = basename($_FILES['txt_resume']['name']);
$email_from = "jaybharatjay@gmail.com";
$email_subject = "jay attach mail testing/tutorial";
$email_txt = "This is testing mail attach sending";
$email_to = $_REQUEST[txt_email];
$headers = "From: ".$email_from;
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$toaddress = $email;
$subject = "Your homework submission!";
$firstname=$_POST['txt_firstname'];
$lastname=$_POST['txt_lastname'];
$email=$_POST['txt_email'];
$message=$_POST['message'];
$email_message .= "
<html>
<head>
<title>Sarika</title>
</head>
<body>
<table>
<tr>
<td>Dear $firstname</td>
</tr>
<tr>
<td>Your details,</td>
</tr>
<tr>
<td><b>First Name:<b> $firstname</td>
</tr>
<tr>
<td><be>Last Name:<b> $lastname</td>
</tr>
<tr>
<td><be>Message:<b> nl2br($message)</td>
</tr>
<tr>
<td>Email: $email</td>
</tr>
<tr>
<td>Regards</td>
</tr>
<tr>
<td>ADMIN jaybharatjay@gmail.com</td>
</tr>
</table>
</body>
</html>
";
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message . "\n\n";
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
$ok = @mail($email_to, $email_subject, $email_message, $headers);
if($ok)
{
echo "<font face=verdana size=2>The Attach Email with File was successfully sent! TO Mr.&nbsp;$email_to</font>";
}
else
{
die("Sorry but the email could not be sent.Check plz offline or online servere. Please go back and try again! TO Mr.&nbsp;$email_to");
}
$file = $uploadfile;
if (!unlink($file))
{
echo ("Error deleting $file");
}
/*else
{
echo ("Deleted $file");
}*/
}//if move upload file close
//attach mail sending close
}
}
else
{
echo "You should Enter the required fields";
}
?>

Comments are closed