初始化代碼
- <?php
- require("PHPMailerAutoload.php"); //引入文件(把剛纔解壓的那些文件放到對應的路徑就可以了)
- $mail = new PHPMailer(); //實例化
- $mail->IsSMTP(); // 啓用SMTP
- $mail->Host="smtp.exmail.qq.com"; //smtp服務器的名稱(這裏以126郵箱爲例)
- $mail->SMTPAuth = true; //啓用smtp認證
- $mail->Username = "[email protected]"; //你的郵箱名
- $mail->Password = "*********"; //郵箱密碼
- $mail->From = "[email protected]"; //發件人地址(也就是你的郵箱地址)
- $mail->FromName = "cnsecer"; //發件人姓名
- $mail->AddAddress("[email protected]","name");
- $mail->AddReplyTo("[email protected]", "****"); //回覆地址(可填可不填)
- $mail->WordWrap = 50; //設置每行字符長度
- //$mail->AddAttachment("images/01.jpg", "manu.jpg"); // 添加附件,並指定名稱
- $mail->IsHTML(true); // 是否HTML格式郵件
- $mail->CharSet="utf-8"; //設置郵件編碼
- $mail->Subject ="test email"; //郵件主題
- $mail->Body = "hello world"; //郵件內容
- $mail->AltBody = "This is the body in plain text for non-HTML mail clients"; //郵件正文不支持HTML的備用顯示
- if(!$mail->Send()) {
- echo "Message could not be sent. <p>";
- echo "Mailer Error: " . $mail->ErrorInfo;
- exit();
- } else {
- echo "Message has been sent";
- }
- ?>
-