<?php
echo "<form action='$PHP_SELF' enctype='multipart/form-data' method='post'>\n";
echo "<input type='text' name='from'><br>\n";
echo "<input type='text' name='to'><br>\n";
echo "<input type='text' name='subject'><br>\n";
echo "<input type='file' name='attachment'><br>\n";
echo "<textarea name='body'></textarea><br>\n";
echo "<input type='submit' name='send' value='Send'>\n";
echo "</form>\n"; # 如果用户已经按了"Send"按钮"
if ($send) {
$boundary = uniqid( ""); # 生成邮件头
$headers = "From: $from
Content-type: multipart/mixed; boundary=\"$boundary\""; # 确定上传文件的MIME类型
if ($attachment_type) $mimeType = $attachment_type;
# 如果浏览器没有指定文件的MIME类型,
# 我们可以把它设为"application/unknown".
else $mimeType = "application/unknown"; # 确定文件的名字
$fileName = $attachment_name; # 打开文件
$fp = fopen($attachment, "r");
# 把整个文件读入一个变量
$read = fread($fp, filesize($attachment)); # 好,现在变量$read中保存的是包含整个文件内容的文本块。
# 现在我们要把这个文本块转换成邮件程序可以读懂的格式
# 我们用base64方法把它编码
$read = base64_encode($read); # 现在我们有一个用base64方法编码的长字符串。
# 下一件事是要把这个长字符串切成由每行76个字符组成的小块
$read = chunk_split($read); # 现在我们可以建立邮件的主体
$body = "--$boundary
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 8bit $body --$boundary
Content-type: $mimeType; name=$fileName
Content-disposition: attachment; filename=$fileName
Content-transfer-encoding: base64 $read --$boundary--"; # 发送邮件
mail($to, $subject, $body, $headers);
}
?>
echo "<form action='$PHP_SELF' enctype='multipart/form-data' method='post'>\n";
echo "<input type='text' name='from'><br>\n";
echo "<input type='text' name='to'><br>\n";
echo "<input type='text' name='subject'><br>\n";
echo "<input type='file' name='attachment'><br>\n";
echo "<textarea name='body'></textarea><br>\n";
echo "<input type='submit' name='send' value='Send'>\n";
echo "</form>\n"; # 如果用户已经按了"Send"按钮"
if ($send) {
$boundary = uniqid( ""); # 生成邮件头
$headers = "From: $from
Content-type: multipart/mixed; boundary=\"$boundary\""; # 确定上传文件的MIME类型
if ($attachment_type) $mimeType = $attachment_type;
# 如果浏览器没有指定文件的MIME类型,
# 我们可以把它设为"application/unknown".
else $mimeType = "application/unknown"; # 确定文件的名字
$fileName = $attachment_name; # 打开文件
$fp = fopen($attachment, "r");
# 把整个文件读入一个变量
$read = fread($fp, filesize($attachment)); # 好,现在变量$read中保存的是包含整个文件内容的文本块。
# 现在我们要把这个文本块转换成邮件程序可以读懂的格式
# 我们用base64方法把它编码
$read = base64_encode($read); # 现在我们有一个用base64方法编码的长字符串。
# 下一件事是要把这个长字符串切成由每行76个字符组成的小块
$read = chunk_split($read); # 现在我们可以建立邮件的主体
$body = "--$boundary
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 8bit $body --$boundary
Content-type: $mimeType; name=$fileName
Content-disposition: attachment; filename=$fileName
Content-transfer-encoding: base64 $read --$boundary--"; # 发送邮件
mail($to, $subject, $body, $headers);
}
?>
解决方案 »
- 为什么有些php网页显示数据,但其html源文件中却没有找到相应的代码会是怎么回事?
- 紧急求助!!SWFObject 文字显示不全
- 新人!!字符串处理的问题。。。
- 偶尔会无缘无故的向MYSQL写入两次数据,头大
- 多php服务器实现多session并发运行
- 请帮忙看看这个问题
- PHP拿来当Shell Script状态下在,怎么向远程post或者get数据阿?我用下面方法单独测试可以,加入到shell中就有问题!请指教!
- 请求帮助session的问题,详细如下:
- 谁有webmail的代码
- 求助!如何对数组的键名首字母进行排序
- 紧急求助 这段PHP+sql写的哪有错误?
- crontab设置正确吗,怎么不能自动运行
--------------------------------------------no submit??? how can you transmit the data of the mail to the mail server?
还有可以检查是不是少了空行。
Content-Type: application/vnd.ms-excel;
name="xxx"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="xxx"
$from = "**@163.com";
$subject = "subject";
$attachment = "/www/logphp/f.xls";
$fileName = "f.xls"; $boundary = uniqid(""); # 生成邮件头
$headers = "From: $from
Content-type: multipart/mixed; boundary=\"$boundary\""; # 打开文件
$fp = fopen($attachment, "r");
# 把整个文件读入一个变量
$read = fread($fp, filesize($attachment)); # 好,现在变量$read中保存的是包含整个文件内容的文本块。
# 现在我们要把这个文本块转换成邮件程序可以读懂的格式
# 我们用base64方法把它编码
$read = base64_encode($read); # 现在我们有一个用base64方法编码的长字符串。
# 下一件事是要把这个长字符串切成由每行76个字符组成的小块
$read = chunk_split($read); # 现在我们可以建立邮件的主体
$body = "--$boundary
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 8bit $body --$boundary
Content-Type: application/vnd.ms-excel;
name=$fileName
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename=$fileName
$read --$boundary--"; # 发送邮件
mail($to, $subject, $body, $headers);