本文介绍了使用attechment发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

我在Mail中获取技术有问题.
邮件已通过attechment成功发送.
但是attechment采用的是加密形式,而不是真正的下载文件.
这是我的代码.

Hello Friends,

I hava a problem to get attechment in Mail.
Mail is successfully send with attechment.
but attechment is in encrypt form not a real download file.
here is my code.

<<blockquote class="FQ"><div class="FQA">Quote:</div>!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
// if there is post
if(isset($_POST) && !empty($_POST))
{
	//if there is an attechment
	if(!empty($_FILES['attechment']['name']))
	{
		// Store in some variable
		$file_name=$_FILES['attechment']['name'];
		$temp_name=$_FILES['attechment']['tmp_name'];
		$file_type=$_FILES['attechment']['type'];
		
		//get the extension of the file
		$base = basename($file_name);
		$extension = substr($base,strlen($base)-4,strlen($base));
		
		// only these file type will be allowed
		
		$allowed_extension = array(".doc",".docx",".text",".txt",".pdf");
		
		// Check that this file type is allowd
		if(in_array($extension,$allowed_extension))
		{
			// Mail essenstials
			$from = $_POST['email'];
			$to = "[email protected]";
			$subject="This is test Mail";
			$message="This is random message";
			
			//things you need
			
			$file = $temp_name;
			$content = file_get_contents($file);
			$uid = md5(uniqid(time()));
			
			//standard mail headers
			
			$header = "From: ".$from."\r\n";
			$header .= "MIME-Version: 1.0\r\n ";
			
			//declaring we have multiple kinds of email (i.e Plain text and attechment)
			
			$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
			$header .= "This is a multi-part message in MIME formate. \r\n";
			
			// Plain text part
			
			$header .= "--".$uid."\r\n";
			$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
			$header .= "Content-Transfer-Encoding: 7bit \r\n\r\n";
			$header .= $message."\r\n\r\n";
			
			//File attechment
			
			$header .= "--".$uid."\r\n";
			$header .= "Content-Type: ".$file_type."; name=\"".$file_name."\"\r\n";
			$header .= "Content-Transfer-Encoding: base64 \r\n";
			$header .= "Content-Disposition: attechment; filename=\"".$file_name."\"\r\n";
			$header .= $content."\r\n\r\n";
			
			
			//send the mail(message is not here but in the header in multiple way)
			
			if(mail($to,$subject,$content,$header))
			{
				echo "Sucess";
			}
			else
			{
				echo "Fail";
			}
				
		}
		else
		{
			echo "File type is not allowed";
		}
	}
	else
	{
		echo "no File posted";
	}
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>attechment</title>
</head>

<body>
<form enctype="multipart/form-data" action="attechment.php" method="post">
<input type="text" name="email" value="from" />
<br />
<input type="file" name="attechment" />
<br />
<input type="submit" name="Send Mail" />
</form>
</body>
</html>

推荐答案




这篇关于使用attechment发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 17:50