PHP發郵件(使用phpmailer)

require_once("phpmailer/class.phpmailer.php");
// 參數說明(收件郵箱,收件姓名, 郵件主題, 郵件內容, 附加信息, 用戶名)
function smtp_mail ( $sendto_email,$sendto_name, $subject, $body, $reply_email, $reply_name) { 
     $mail = new PHPMailer(); 
     $mail->IsSMTP();                // send via SMTP 
     $mail->Host = "xxxxxxxxx"; // SMTP servers
     $mail->SMTPAuth = true;         // turn on SMTP authentication 
     $mail->Username = "xxxxxxxxx";   // SMTP username  注意:普通郵件認證不須要加 @域名 
     $mail->Password = "xxxxxxxxx";        // SMTP password 
     $mail->From = "xxxxxxxxx";      // 發件人郵箱 
     $mail->FromName =  "人事部";  // 發件人 
     $mail->CharSet = "utf-8";            // 這裏指定字符集!
     $mail->Encoding = "base64"; 
     $mail->AddAddress($sendto_email,$sendto_name);  // 收件人郵箱和姓名 
     $mail->AddReplyTo($reply_email,$reply_name); //回覆地址和姓名
     $mail->WordWrap = 50; // set word wrap 
     $mail->IsHTML(true);  // send as HTML 
     $mail->Subject = $subject;  // 郵件主題
     $mail->Body = $body;
     $mail->AltBody ="text/html"; 
     if(!$mail->Send()){ 
          echo $sendto_name."郵件發送有誤,"; 
          echo "郵件錯誤信息: " . $mail->ErrorInfo. "<br />";
          exit; 
     } else { 
          echo "郵件已發送到 ".$sendto_name.' 的 '.$sendto_email."郵箱. <br />"; 
     }
}php

運行方式:直接調用smtp_mail 函數html

相關文章
相關標籤/搜索