 

<?php
require("class.phpmailer.php");
$file = $_FILES["uploadfile"]["tmp_name"];
if($file)
{	
	$userpic = $_FILES["uploadfile"]["name"];
	$path = "temp/".$userpic;
	move_uploaded_file($file,$path);
}
$mail       = new PHPMailer();
$address    = $_POST['address'];
$uploadfile = $_POST['uploadfile'];
$Subject    = $_POST['Subject'];
$Body       = $_POST['content'];
$smtpname   = $_POST['smtpname'];
$myaddress  = $_POST['myaddress'];
$password   = $_POST['password'];
$myname     = $_POST['myname'];

$mail->IsSMTP();             // set mailer to use SMTP
$mail->Host     =$smtpname;  // specify main and backup server
$mail->SMTPAuth =true;       // turn on SMTP authentication
$mail->Username =$myaddress; // SMTP username
$mail->Password =$password;  // SMTP password
$mail->From     =$myaddress; 
$mail->FromName =$myname;   
$mail->AddAddress("$address","");

//$mail->AddAddress(""); // name is optional
//$mail->AddReplyTo("", "");
//$mail->WordWrap = 50; // set word wrap to 50 characters

if (file_exists($path))
{
	$mail->AddAttachment("temp/".$userpic); // add attachments
}
else<br />
{

}
//$mail->AddAttachment("tmp/".$userpic,$userpic); // optional name
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = $Subject;
$mail->Body    = $Body;
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send())
{
	if (file_exists($path))
    {
      unlink($path);
    }
    echo $mail->ErrorInfo;
    echo "<div align=center><span style='font-size:12px;padding-top:100px;color:#FF0000;'>邮件无法发送！&nbsp;&nbsp;&nbsp;<input type=\"button\" value=\" 返 回 \" name=\"button\"    onclick=\"location.href='javascript:history.back();'\"style='font-size:12px;padding-top: 3px;border-right: #c5d7e2 1px solid;border-top: #c5d7e2 1px solid;border-left: #c5d7e2 1px solid;border-bottom: #c5d7e2 1px solid;background-color: #dde8e3;'></span>";
    exit;
}
if (file_exists($path))
{
    unlink($path);
}
echo "<div align=center><span style='font-size:12px;margin-top:100px;'>邮件发送成功&nbsp;&nbsp;&nbsp;<input type=\"button\" value=\" 返 回 \" name=\"button\" onclick=\"location.href='../email_sendform.php'\"style='font-size:12px;padding-top: 3px;border-right: #c5d7e2 1px solid;border-top: #c5d7e2 1px solid;border-left: #c5d7e2 1px solid;border-bottom: #c5d7e2 1px solid;background-color: #dde8e3;'></span>";

?>
