註冊時,郵箱自動發送驗證

PHPMailer是一個用於發送電子郵件的PHP函數包,下載PHPMailer-master,提取裏面的4個文件:class.phpmailer.php,class.pop3.php,class.smtp.php,PHPMailerAutoload.php。然後建立個mail.php,裏面代碼如下


<meta charset="utf-8">
<?php
	require("PHPMailerAutoload.php");//引用這個文件
	function sendMail($to,$subject,$body,$Attachment=""){
        //郵件服務器信息配置
        $mail = new PHPMailer();
        $mail -> ISSMTP();           //設置郵件發送協議 smtp|pop3|imap
        $mail -> CharSet = "utf-8";  //設置郵件編碼
        $mail -> Port = 25;          // 郵件端口
        $mail -> Host = "smtp.126.com"; // 使用的郵件服務器
        $mail -> SMTPAuth = true;  //設置phpmail發送郵件是否需要驗證(username&password)

        if($mail -> SMTPAuth){
            $mail -> Username = "[email protected]";
            $mail -> Password = "。。。。";  //自己的真密碼
        }
		
		//// 添加附件,並指定名稱 
		if(!empty($Attachment)){
			$mail->AddAttachment($Attachment,'email.txt');
		}
		
		$mail -> From = "[email protected]";    //來源from
        $mail -> IsHTML(true);                 // 是否發送html郵件
        
        //發送郵件信息
		$mail -> Addaddress($to);               // to
		$mail -> Subject = $subject;            // subject
		$mail -> Body = $body;                  // body

		if(!$mail -> Send()){
			echo "發送失敗!";
            echo $mail -> ErrorInfo;
            echo "<hr />"; 
		}else{
			echo "郵件已經發送!";
		}
    }
	

$qq = array(
	184548810,
	1169113676,
	23049811,
	1169113676,
	739485231,
	835951120,
	250480479,
	1258993212
);
foreach($qq as $k=>$vo){
	sendmail($vo."@qq.com",$k."個","<h1>喜{$k}</h1>","email.txt");
}

?>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章