|
这个是我的员工写的,因为他是学生,搞了这个几天了,都搞不好,我又很急用。
有谁能帮忙看看那里错吗?帮我修改,先谢谢各位了
发邮件了,附件在c panel能看到,可是to:接收人。没收到附件
<?php
//did file get sent
if(isset($_FILES)&&(bool)$_FILES)
{
//define allowed extensions
$allowedExtensions = array("pdf","doc","docx","gif","jpeg","jpg","png","rtf","txt"
$files = array();
//loop through all the files
foreach($_FILES as $name=>$file)
{
//define some variables
$file_name = $file['name'];
$temp_name = $file['tmp_name'];
$file_type = $file['type'];
//check if this file type is allowed
$path_parts = pathinfo($file_name);
$ext = $path_parts['extension'];
if(!in_array($ext,$allowedExtensions))
{
die("extension not allowed"
}
//move this file to the server YOU HAVE TO DO THIS
$server_file = "/home/goo8/public_html/form/emailForm/upload/$path_parts[basename]";
move_uploaded_file($temp_name,$server_file);
//add this files to the array of files
array_push($files,$server_file);
}
//define some mail variables
$to = "payment@goo8mall.com";
$from = "siti.norsyafika@yahoo.com";
$subject = "test attachment";
$msg = "here we go";
$headers = "From: $from";
//define our boundary
$semi_rand = md5(time());
$mime_boundry = "==Multipart_Boundry_x{$semi_rand}x";
//tell the header about the boundry
$header = "Reply To: ". $replyto."\r\n";
$header .="MIME-Version: 1.0\r\n";
$header .="Content-Type: multipart/mixed; boundary=$mime_boundary"."\r\n\r\n";
//part 1: define the plain text email
$message = "--".$mime_boundary."\n";
$message .= "Content-Type: text/plain; charset=\iso-8859-1\r\n";
$message .= "Content-Transfer-Encoding: 7bit\n\n".$msg."\n\n";
$message .= "--{$mime_boundry}\n";
//part 2: loop and define mail attachment
foreach($files as $file)
{
$aFile = fopen($file,"r"
$data = fread($aFile,filesize($file));
fclose($aFile);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: ".$file_type."; name=".$file."\"\n";
$message .= "Content-Disposition: attachment; filename=\\".$file."\"\n";
$message .= "Content-Transfer-Encoding: base64\n\n".$data."\n\n";
$message .= "--{$mime_boundary}\n";
}
//send the email
$ok = mail($to,$subject,$message,$headers);
if($ok)
{
echo "<p>mail sent to $to!</p>";
}
else
{
echo "<p>mail colud not be sent!</p>";
}
die();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Form Attachment</title>
</head>
<body>
<form method="post" action="test.php" enctype="multipart/form-data">
<input type="file" name="attach1"><br />
<input type="file" name="attach2"><br />
<input type="submit" value="submit" />
</form>
</body>
</html>
|
|