我发送带有docx或pdf格式的简历的电子邮件。我设法在服务器上传文件并发送电子邮件。但是,当我收到时,我无法下载附件。然后在显示警告后自行下载。当我打开它时,结果是空白!可能是什么原因?以下是相关文件。谢谢。
sendmail.php
<?php
session_start();
$username = $_SESSION['username'];
$password = $_SESSION['password'];
//Check do we have username and password
?>
<!DOCTYPE HTML>
<HTML><HEAD><TITLE><?php echo $row_RecWebConfig['config_title']; ?> - <?php echo $row_RecContent['CntName']; ?></TITLE>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Description" content="<?php echo $row_RecContent['Description']; ?>">
<meta name="KeyWords" content="<?php echo $row_RecContent['Keywords']; ?>">
<link REL="SHORTCUT ICON" HREF="favicon.ico">
<LINK rel=stylesheet type=text/css
href="content.css"><LINK rel=stylesheet type=text/css
href="cart.css">
<SCRIPT type=text/javascript src="jquery-1.6.X.min.js"></SCRIPT>
<!--DROP DOWN MENU START--><LINK rel=stylesheet type=text/css
href="style.css"><!--[if lte IE 7]>
<link href="ie.css" type="text/css" rel="stylesheet" />
<![endif]--><!--DROP DOWN MENU END--><!--CSS BUTTONS START--><LINK
rel=stylesheet type=text/css href="css3buttons.css"><!--CSS BUTTONS END--><!-- THE LEAD CODER AT MOBIPOT KEATLIANG2005[AT]GMAIL[DOT]COM --><!-- THE LEAD CODER AT MOBIPOT KEATLIANG2005[AT]GMAIL[DOT]COM -->
<SCRIPT type=text/javascript src="jquery.slider.js"></SCRIPT>
<!-- THE LEAD CODER AT MOBIPOT KEATLIANG2005[AT]GMAIL[DOT]COM --><!-- THE LEAD CODER AT MOBIPOT KEATLIANG2005[AT]GMAIL[DOT]COM -->
<SCRIPT type=text/javascript>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-25360251-11']);
_gaq.push(['_trackPageview']);
(function(){
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</SCRIPT>
<!-- THE LEAD CODER AT MOBIPOT KEATLIANG2005[AT]GMAIL[DOT]COM --><!-- THE LEAD CODER AT MOBIPOT KEATLIANG2005[AT]GMAIL[DOT]COM -->
<SCRIPT type=text/javascript src="pirobox.min.js"></SCRIPT>
<LINK rel=stylesheet type=text/css href="global.css">
<SCRIPT language=javascript type=text/javascript>
$(function(){
$().piroBox({ my_speed: 300, bg_alpha: 0.5, slideShow: true, slideSpeed: 3 });
})
</SCRIPT>
<LINK rel=stylesheet type=text/css href="category.css"><!--[if lt IE 8]><link href="category-ie.css" type="text/css" rel="stylesheet" />
<![endif]-->
<!--<LINK rel=stylesheet type=text/css href="style-gallery.css">
-->
<META name=GENERATOR content="MSHTML 8.00.7600.16722"></HEAD>
<BODY>
<DIV class=global_wrap>
<?php include('header.php'); ?>
<DIV class=clear></DIV>
<?php include('banner.php'); ?>
<DIV class=clear></DIV>
<DIV id=wrapper_content>
<DIV id=top_container></DIV>
<DIV id=body_container_2>
<DIV id=quickfacts class=auto_margin>
<DIV id=whitecontainer style="padding-left:30px; padding-right:35px">
<h1></h1></DIV></DIV>
<?php
$allowedExts = array("pdf", "doc", "docx");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if (($_FILES["file"]["type"] == "application/pdf") || ($_FILES["file"]["type"] == "application/msword") || ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")&& ($_FILES["file"]["size"] < 80000)
&& in_array($extension, $allowedExts)) {
if ($_FILES["file"]["error"] > 0) {
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
} else {
/* echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";*/
/* if (file_exists("upload/" . $_FILES["file"]["name"])) {
echo $_FILES["file"]["name"] . " already exists. ";
} else {*/
$file=uniqid('')."_".$_FILES["file"]["name"];
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" .$file);
/*echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
echo "<span style='padding-left:30px;'>File Attached:".$_FILES["file"]["name"]."</span><br><br>";*/
echo"<span style='padding-left:30px;'>Fill up below form to send out email</span><br>";
}
} else {
echo "Invalid file";
}
?>
<html>
<head>
<title></title>
</head>
<Body>
<form name="form1" method="post" action="mail.php">
<table width="auto" border="0" align="center">
<tr><td><div align="right">File Attached:</div></td><td>
<input name="name" type="text" id="name" value="<?php echo $_FILES["file"]["name"]; ?>">
</td></tr>
<tr>
<td><div align="right">Name:</div></td>
<td><input name="nume" type="text" id="nume">
</td>
</tr>
<tr>
<td><div align="right">Surname:</div></td>
<td><input name="prenume" type="text" id="prenume"></td>
</tr>
<tr>
<td><div align="right">*Sender E- mail: </div></td>
<td><input name="email" type="text" id="email"></td>
</tr>
<tr>
<td><div align="right">Aplication for : </div></td>
<td><input name="post" type="text" id="post"></td>
</tr>
</table>
<p>
<span style='padding-left:30px;'><input type="submit" name="Submit" value="Next >>>"></span>
</p>
</form>
</DIV><!--end body_container"-->
<DIV id=bottom_container2></DIV>
<DIV class=clear></DIV></DIV><!--end wrapper_content--></DIV><!--end global_wrap-->
<?php include('footer.php'); ?></BODY></HTML>
mail.php
<?php
session_start();
$username = $_SESSION['username'];
$password = $_SESSION['password'];
//Check do we have username and password
?>
<!DOCTYPE HTML>
<HTML><HEAD><TITLE><?php echo $row_RecWebConfig['config_title']; ?> - <?php echo $row_RecContent['CntName']; ?></TITLE>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Description" content="<?php echo $row_RecContent['Description']; ?>">
<meta name="KeyWords" content="<?php echo $row_RecContent['Keywords']; ?>">
<link REL="SHORTCUT ICON" HREF="favicon.ico">
<LINK rel=stylesheet type=text/css
href="content.css"><LINK rel=stylesheet type=text/css
href="cart.css">
<SCRIPT type=text/javascript src="jquery-1.6.X.min.js"></SCRIPT>
<!--DROP DOWN MENU START--><LINK rel=stylesheet type=text/css
href="style.css"><!--[if lte IE 7]>
<link href="ie.css" type="text/css" rel="stylesheet" />
<![endif]--><!--DROP DOWN MENU END--><!--CSS BUTTONS START--><LINK
rel=stylesheet type=text/css href="css3buttons.css"><!--CSS BUTTONS END--><!-- THE LEAD CODER AT MOBIPOT KEATLIANG2005[AT]GMAIL[DOT]COM --><!-- THE LEAD CODER AT MOBIPOT KEATLIANG2005[AT]GMAIL[DOT]COM -->
<SCRIPT type=text/javascript src="jquery.slider.js"></SCRIPT>
<!-- THE LEAD CODER AT MOBIPOT KEATLIANG2005[AT]GMAIL[DOT]COM --><!-- THE LEAD CODER AT MOBIPOT KEATLIANG2005[AT]GMAIL[DOT]COM -->
<SCRIPT type=text/javascript>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-25360251-11']);
_gaq.push(['_trackPageview']);
(function(){
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</SCRIPT>
<!-- THE LEAD CODER AT MOBIPOT KEATLIANG2005[AT]GMAIL[DOT]COM --><!-- THE LEAD CODER AT MOBIPOT KEATLIANG2005[AT]GMAIL[DOT]COM -->
<SCRIPT type=text/javascript src="pirobox.min.js"></SCRIPT>
<LINK rel=stylesheet type=text/css href="global.css">
<SCRIPT language=javascript type=text/javascript>
$(function(){
$().piroBox({ my_speed: 300, bg_alpha: 0.5, slideShow: true, slideSpeed: 3 });
})
</SCRIPT>
<LINK rel=stylesheet type=text/css href="category.css"><!--[if lt IE 8]><link href="category-ie.css" type="text/css" rel="stylesheet" />
<![endif]-->
<!--<LINK rel=stylesheet type=text/css href="style-gallery.css">
-->
<META name=GENERATOR content="MSHTML 8.00.7600.16722"></HEAD>
<BODY>
<DIV class=global_wrap>
<?php include('header.php'); ?>
<DIV class=clear></DIV>
<?php include('banner.php'); ?>
<DIV class=clear></DIV>
<DIV id=wrapper_content>
<DIV id=top_container></DIV>
<DIV id=body_container_2>
<DIV id=quickfacts class=auto_margin>
<DIV id=whitecontainer style="padding-left:30px; padding-right:35px">
<h1></h1></DIV></DIV>
<?php
if(isset($_POST["Submit"]))
{
if(empty($_POST['email']))
{
$email=NULL;
echo"<span style='padding-left:30px;'>Your email must not be empty!Please go back and fill up.</span><br>";
echo '<span style="padding-left:30px;"><INPUT Type="button" VALUE="Back" onClick="history.go(-1);return true;"></span>';
}
else
{
//to be successfull in useing this code you need to create a directory called upload
//on you ftp create a directory upload in wich copy the content of the zip file
//$filleant takes the value of the picture that was jut uploaded with the unique name to the ftp in the www.yourname.com/upload/upload
$fileatt = "www.example.com/upload/".$_POST["name"]; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
//here i made the file that will be sent as attachment to have the name "CV_name_surname.doc" you can make it what format you like,
//i needed the doc format... and i'll modify this code to accept just doc file later...i'm really tired right now :D
$fileatt_name = "CV_".$_POST['nume']."_".$_POST['prenume'].".doc"; // Filename that will be used for the file as the attachment
//$email_from is the variable that gets the value, of the From: field that will appear in your received mail
$email_from = $_POST['nume']." ".$_POST['prenume']; // Who the email is from
//Here you define the subject of you message
$email_subject = "CV."; // The Subject of the email
//here you define the body of the message, the message itself
//you can modify the "post" textfield in sendmail.php to a textarea....
$email_message = $_POST['post']; // Message that the email has in it
//here you enter the e-mail address to wich you want the message to be sent
$email_to = "kalaivaninair@ymail.com"; // Who the email is too
//adds the e-mail address of the sender
$headers = "From: ".$_POST['email'];
$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}\"";
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/plain; charset=\"iso-8859-1\"" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message . "\n\n";
/********************************************** First File ********************************************/
//$filleant takes the value of the picture that was jut uploaded with the unique name to the ftp in the www.yourname.com/upload/upload
$fileatt = "www.pmw-industries.com/upload/".$_POST["name"]; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
//here i made the file that will be sent as attachment to have the name "CV_name_surname.doc" you can make it what format you like,
//i needed the doc format... and i'll modify this code to accept just doc file later...i'm really tired right now :D
$fileatt_name = "CV".$_POST['nume']."_".$_POST['prenume'].".docx"; // Filename that will be used for the file as the attachment
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$output = ob_get_flush();
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Disposition: attachment;" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}\n";
unset($data);
unset($file);
unset($fileatt);
unset($fileatt_type);
unset($fileatt_name);
/********************************************** End of File Config ********************************************/
// To add more files just copy the file section again, but make sure they are all one after the other! If they are not it will not work!
$ok = @mail($email_to, $email_subject, $email_message, $headers);
if($ok) {
echo "<span style='padding-left:30px;'><font face=verdana size=2>The email was successfully sent!</font></span>";
} else {
die("Sorry but the email could not be sent. Please go back and try again!");
} }}
?>
</DIV><!--end body_container"-->
<DIV id=bottom_container2></DIV>
<DIV class=clear></DIV></DIV><!--end wrapper_content--></DIV><!--end global_wrap-->
<?php include('footer.php'); ?></BODY></HTML>
答案 0 :(得分:0)
尝试编辑
<?php
session_start();
$username = $_SESSION['username'];
$password = $_SESSION['password'];
//Check do we have username and password
?>
<!DOCTYPE HTML>
<HTML><HEAD><TITLE><?php echo $row_RecWebConfig['config_title']; ?> - <?php echo $row_RecContent['CntName']; ?></TITLE>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Description" content="<?php echo $row_RecContent['Description']; ?>">
<meta name="KeyWords" content="<?php echo $row_RecContent['Keywords']; ?>">
<link REL="SHORTCUT ICON" HREF="favicon.ico">
<LINK rel=stylesheet type=text/css
href="content.css"><LINK rel=stylesheet type=text/css
href="cart.css">
<SCRIPT type=text/javascript src="jquery-1.6.X.min.js"></SCRIPT>
<!--DROP DOWN MENU START--><LINK rel=stylesheet type=text/css
href="style.css"><!--[if lte IE 7]>
<link href="ie.css" type="text/css" rel="stylesheet" />
<![endif]--><!--DROP DOWN MENU END--><!--CSS BUTTONS START--><LINK
rel=stylesheet type=text/css href="css3buttons.css"><!--CSS BUTTONS END--><!-- THE LEAD CODER AT MOBIPOT KEATLIANG2005[AT]GMAIL[DOT]COM --><!-- THE LEAD CODER AT MOBIPOT KEATLIANG2005[AT]GMAIL[DOT]COM -->
<SCRIPT type=text/javascript src="jquery.slider.js"></SCRIPT>
<!-- THE LEAD CODER AT MOBIPOT KEATLIANG2005[AT]GMAIL[DOT]COM --><!-- THE LEAD CODER AT MOBIPOT KEATLIANG2005[AT]GMAIL[DOT]COM -->
<SCRIPT type=text/javascript>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-25360251-11']);
_gaq.push(['_trackPageview']);
(function(){
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</SCRIPT>
<!-- THE LEAD CODER AT MOBIPOT KEATLIANG2005[AT]GMAIL[DOT]COM --><!-- THE LEAD CODER AT MOBIPOT KEATLIANG2005[AT]GMAIL[DOT]COM -->
<SCRIPT type=text/javascript src="pirobox.min.js"></SCRIPT>
<LINK rel=stylesheet type=text/css href="global.css">
<SCRIPT language=javascript type=text/javascript>
$(function(){
$().piroBox({ my_speed: 300, bg_alpha: 0.5, slideShow: true, slideSpeed: 3 });
})
</SCRIPT>
<LINK rel=stylesheet type=text/css href="category.css"><!--[if lt IE 8]><link href="category-ie.css" type="text/css" rel="stylesheet" />
<![endif]-->
<!--<LINK rel=stylesheet type=text/css href="style-gallery.css">
-->
<META name=GENERATOR content="MSHTML 8.00.7600.16722"></HEAD>
<BODY>
<DIV class=global_wrap>
<?php include('header.php'); ?>
<DIV class=clear></DIV>
<?php include('banner.php'); ?>
<DIV class=clear></DIV>
<DIV id=wrapper_content>
<DIV id=top_container></DIV>
<DIV id=body_container_2>
<DIV id=quickfacts class=auto_margin>
<DIV id=whitecontainer style="padding-left:30px; padding-right:35px">
<h1></h1></DIV></DIV>
<?php
if(isset($_POST["Submit"]))
{
if(empty($_POST['email']))
{
$email=NULL;
echo"<span style='padding-left:30px;'>Your email must not be empty!Please go back and fill up.</span><br>";
echo '<span style="padding-left:30px;"><INPUT Type="button" VALUE="Back" onClick="history.go(-1);return true;"></span>';
}
else
{
//to be successfull in useing this code you need to create a directory called upload
//on you ftp create a directory upload in wich copy the content of the zip file
//$filleant takes the value of the picture that was jut uploaded with the unique name to the ftp in the www.yourname.com/upload/upload
$fileatt = "www.pmw-industries.com/upload/".$_POST["name"]; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
//here i made the file that will be sent as attachment to have the name "CV_name_surname.doc" you can make it what format you like,
//i needed the doc format... and i'll modify this code to accept just doc file later...i'm really tired right now :D
$fileatt_name = "CV_".$_POST['nume']."_".$_POST['prenume'].".doc"; // Filename that will be used for the file as the attachment
//$email_from is the variable that gets the value, of the From: field that will appear in your received mail
$email_from = $_POST['nume']." ".$_POST['prenume']; // Who the email is from
//Here you define the subject of you message
$email_subject = "CV."; // The Subject of the email
//here you define the body of the message, the message itself
//you can modify the "post" textfield in sendmail.php to a textarea....
$email_message = $_POST['post']; // Message that the email has in it
//here you enter the e-mail address to wich you want the message to be sent
$email_to = "kalaivaninair@ymail.com"; // Who the email is too
//adds the e-mail address of the sender
$headers = "From: ".$_POST['email'];
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\r\nMIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed; boundary=\"{$mime_boundary}\"";
$email_message .= "This is a multi-part message in MIME format.\r\n\r\n" .
"--{$mime_boundary}\r\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\r\n" .
"Content-Transfer-Encoding: 7bit\r\n\r\n" .
$email_message . "\r\n\r\n";
/********************************************** First File ********************************************/
//$filleant takes the value of the picture that was jut uploaded with the unique name to the ftp in the www.yourname.com/upload/upload
$fileatt = "www.pmw-industries.com/upload/".$_POST["name"]; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
//here i made the file that will be sent as attachment to have the name "CV_name_surname.doc" you can make it what format you like,
//i needed the doc format... and i'll modify this code to accept just doc file later...i'm really tired right now :D
$fileatt_name = "CV".$_POST['nume']."_".$_POST['prenume'].".docx"; // Filename that will be used for the file as the attachment
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$output = ob_get_flush();
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\r\n" .
"Content-Type: {$fileatt_type}; name=\"{$fileatt_name}\"\r\n" .
"Content-Disposition: attachment; filename=\"{$fileatt_name}\"\r\n" .
"Content-Transfer-Encoding: base64\r\n\r\n" .
$data . "\r\n\r\n" .
"--{$mime_boundary}--\r\n";
unset($data);
unset($file);
unset($fileatt);
unset($fileatt_type);
unset($fileatt_name);
/********************************************** End of File Config ********************************************/
// To add more files just copy the file section again, but make sure they are all one after the other! If they are not it will not work!
$ok = @mail($email_to, $email_subject, $email_message, $headers);
if($ok) {
echo "<span style='padding-left:30px;'><font face=verdana size=2>The email was successfully sent!</font></span>";
} else {
die("Sorry but the email could not be sent. Please go back and try again!");
} }}
?>
</DIV><!--end body_container"-->
<DIV id=bottom_container2></DIV>
<DIV class=clear></DIV></DIV><!--end wrapper_content--></DIV><!--end global_wrap-->
<?php include('footer.php'); ?></BODY></HTML>