實例 require_once ('PHPMailer/class.phpmailer.php'); //引入phpmailer文件 require_once ('PHPMailer/class.smtp.php'); $mail=new PHPMailer(); //實例化phpmailer類 $mail->IsSMTP(); $mail->CharSet='UTF-8'; $mail->AddAddress([email protected]); //收件人郵箱 $mail->Body=$content; //發件內容 $mail->[email protected]; //發件人郵箱[email protected] $mail->FromName="zjsupport"; //發件人的名字 $mail->Subject="title"; //郵件標題 $mail->Host="smtp.163.com"; //smtp服務器 $mail->SMTPAuth=true; //開啟smtp服務 $mail->IsHTML(true); //發送附件 $mail->AddAttachment(path,name); //path是附件的保存路徑 name是附件的名字 //可以上傳多個附件,一模一樣復制 $mail->AddAttachment(path,name); 代碼就行 $mail->Username="[email protected] ";//發件人郵箱 $mail->Password="123456";//發件人郵箱密碼 if($mail->Send()){ //判斷郵件是否發送成功 echo "success"; }else{ $email_error=$email_error.";".$val; //若不成功將發送失敗的郵箱存入字符竄 } if($email_error==""){ echo "email_success"; }else{ echo $email_error; }