=========================================================================================
//设置发件者初始信息从这开始
require("class.phpmailer.php");
$ mail = new PHPMailer();
$ uniq_id = md5(uniqid(time()));
$ mail->SetLanguage('cn', "language/");
$ mail->IsSMTP(); // set mailer to use SMTP
$ mail->Host = "smtp.mail.sogou.com;smtp.163.com"; // specify main and backup server
$ mail->SMTPAuth = true; // turn on SMTP authentication
$ mail->Username = "temp@ezpower.cn"; // SMTP username
$ mail->Password = "temp"; // SMTP password
$ mail->From = "temp@ezpower.cn";
$ mail->FromName = "EzPower";
//设置发件者初始信息到这结束;
// 在 4.1.0 以前的 PHP 中,需要用 $ HTTP_POST_FILES 代替 $ _FILES。
// 在 4.0.3 以前的 PHP 中,需要用 copy() 和 is_uploaded_file() 来代替 move_uploaded_file()。
$ mto=$ _REQUEST["mto"];
$ mailcc=$ _REQUEST["mcc"];
$ mailsubject=$ _REQUEST["msubject"];
$ mailbody=$ _REQUEST["mbody"];
//echo ($ mailto.$ mailcc.$ mailbody.$ mailsubject);
$ mto=explode(";",$ mto);
foreach($ mto as $ key=>$ mto1){
if (strpos($ mto1, '@') !== false) {
$ mail->AddAddress($ mto[$ key]);}
};
$ mcc=explode(";",$ mcc);
foreach($ mcc as $ key=>$ mcc1){
if (strpos($ mcc1, '@') !== false) {
$ mail->AddCC($ mcc[$ key]);}
};
$ uploaddir = 'ups/'.date("omdH").'/';//建立ups/当前时间/的文件夹来存放文件
if (@opendir($ uploaddir)){
echo($ uploaddir.' already exist!</br>');
@closedir ($ uploaddir);
}
else
{echo 'Now mkdir will make "'.$ uploaddir.'"for you </br>';
@mkdir($ uploaddir);
}
$ uploadfile = $ uploaddir. $ _FILES['userfile']['name'];
//echo($ uploadfile);
//foreach ($ _FILES['userfile']['name']) {
print "<pre>\n";
//返回一个URL连接
function url($ a,$ b)
{
$ url= "<a href='".$ a.$ b."' title='".$ b."' >".$ b."</a></br>";
return "$ url\n";
}
foreach ($ _FILES["userfile"]["size"] as $ key => $ size) {
if ($ size != 0 ) {
$ tmp_name = $ _FILES["userfile"]["tmp_name"][$ key];
$ name = $ _FILES["userfile"]["name"][$ key];
move_uploaded_file($ tmp_name, $ uploaddir . $ name);
//$ url= "<a href='".$ uploaddir.$ name."' title='".$ name."' >".$ name."</a></br>";
//把附件内容添加到邮件中开始:
$ mail->AddAttachment($ uploaddir . $ name); // add attachments
//把附件内容添加到邮件中结束:
print url($ uploaddir,$ name);
}
}
//从下面开始进行mail发送动作;
//$ mail->AddAddress($ mailto);
//$ mail->AddAddress("temp@ezpower.cn"); // name is optional
$ mail->AddReplyTo("temp@ezpower.cn", "Reply to me");
//$ mail->AddEmbeddedImage("ups/drunk.gif",$ uniq_id,"drunk.gif","base64","image/gif");
//访问嵌入式图片方法为:<img src=cid:$ uniq_id>
$ mail->WordWrap = 50; // set word wrap to 50 characters
//$ mail->AddAttachment("ups/2007050623/Uploader V6 文件上传中文版.rar"); // add attachments
//$ mail->AddAttachment("phpmailer-1.73.zip"); // optional name
$ mail->IsHTML(true); // set email format to HTML
$ mail->Subject = $ mailsubject;
$ mail->Body = $ mailbody;
$ mail->AltBody = "This is the body in plain text for non-HTML mail clients";
set_time_limit(0);//设定最长执行时间,单位为秒,以免因为发送文件而出现TIME_OUT执行错误
if(!$ mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $ mail->ErrorInfo;
exit;
}
echo "Message has been sent";
//邮件发送结束
/*
foreach ($ _FILES["userfile"]["error"] as $ key => $ error) {
if ($ error == UPLOAD_ERR_OK ) {
$ tmp_name = $ _FILES["userfile"]["tmp_name"][$ key];
$ name = $ _FILES["userfile"]["name"][$ key];
move_uploaded_file($ tmp_name, $ uploaddir . $ name);
//$ url= "<a href='".$ uploaddir.$ name."' title='".$ name."' >".$ name."</a></br>";
print url($ uploaddir,$ name);
}
}
*/
print "\nFile is valid, and was successfully uploaded. You can access to your files by clicking below links:\n";
// echo()
print_r($ _FILES);
if ($ handle = opendir($ uploaddir)) {
while (false !== ($ file = readdir($ handle))) {
if ($ file != "." && $ file != "..") {
echo url($ uploaddir,$ file)." \n";
}
}
closedir($ handle);
}
print "</pre>";
?>
===================================================================================