phpmailer發送郵件

來源:互聯網
上載者:User

標籤:add   include   添加   是你   dump   方式   下載   script   http   

1.首先要設定一下發送郵件的郵箱,這裡以163郵箱做測試。

登陸進去之後,在設定裡面開啟POP3/SMTP/服務。(一般設定完授權碼之後,163的郵箱系統會自動給你開啟此服務)

2.下載phpmail類檔案

http://webscripts.softpedia.com/script/PHP-Clases/PHPMailer-Codeworx-Technologies-46188.html

3.代碼

<?php//include("./PHPMailer/class.phpmailer.php");require "./PHPMailer/PHPMailerAutoload.php";$mail = new PHPMailer();$mail->isSMTP(); // 啟用SMTP//$mail->SMTPDebug=1; //開啟偵錯模式//$mail->SMTPSecure = "ssl";$mail->CharSet=‘utf-8‘; //設定郵件編碼格式$mail->Host="smtp.163.com;"; //smtp伺服器的名稱(這裡以163郵箱為例)$mail->SMTPAuth = true; //啟用smtp認證$mail->Username = "******"; //你的郵箱名可以不寫@尾碼,也可以寫$mail->Password = "******"; //郵箱密碼,現在開啟郵箱SMTP後叫做安全碼$mail->Port=25; //SMTP連接埠號碼//$mail->Port = 994;$mail->setFrom("******@163.com","aa"); //寄件者地址(也就是你的郵箱地址)和寄件者名稱$mail->AddAddress("******@qq.com",""); //接收人地址和名稱$mail->WordWrap = 100; //設定每行字元長度$mail->isHTML(true); // 是否HTML格式郵件$mail->Subject ="測試"; //郵件主題$mail->Body = "ceshiceshi"; //郵件內容//$mail->AltBody = "這是一個純文字的身體在非營利的HTML電子郵件用戶端"; //郵件內文不支援HTML的備用顯示var_dump($mail->Send()); //發送方法,發送成功返回true,失敗返回false//echo $mail->ErrorInfo; //擷取錯誤資訊

另一個樣本:

<?phprequire ‘PHPMailerAutoload.php‘;// 載入這1個檔案和載入下面2個檔案的作用是等同的//require_once ‘class.phpmailer.php‘;//require_once ‘class.smtp.php‘;$mail = new PHPMailer();$mail->isSMTP();// 使用SMTP服務$mail->CharSet = "utf8";// 編碼格式為utf8,不設定編碼的話,中文會出現亂碼$mail->Host = "smtp.163.com";// 發送方的SMTP伺服器位址$mail->SMTPAuth = true;// 是否使用身分識別驗證$mail->Username = "[email protected]";// 發送方的163信箱使用者名$mail->Password = "******";// 發送方的郵箱密碼,注意用163郵箱這裡填寫的是“用戶端授權密碼”而不是郵箱的登入密碼!$mail->SMTPSecure = "ssl";// 使用ssl協議方式$mail->Port = 994;// 163郵箱的ssl協議方式連接埠號碼是465/994$mail->setFrom("[email protected]","Mailer");// 設定寄件者資訊,如郵件格式說明中的寄件者,這裡會顯示為Mailer([email protected]),Mailer是當做名字顯示$mail->addAddress("[email protected]",‘Liang‘);// 設定收件者資訊,如郵件格式說明中的收件者,這裡會顯示為Liang([email protected])$mail->addReplyTo("[email protected]","Reply");// 設定回複人資訊,指的是收件者收到郵件後,如果要回複,回複郵件將發送到的郵箱地址$mail->addCC("[email protected]");// 設定郵件抄送人,可以唯寫地址,上述的設定也可以唯寫地址$mail->addBCC("[email protected]");// 設定秘密抄送人$mail->addAttachment("bug0.jpg");// 添加附件$mail->Subject = "This is a test mailxx";// 郵件標題$mail->Body = "This is the html body <b>very stronge非常強壯</b>";// 郵件內文//$mail->AltBody = "This is the plain text純文字";// 這個是設定純文字方式顯示的本文內容,如果不支援Html方式,就會用到這個,基本無用if(!$mail->send()){// 發送郵件    echo "Message could not be sent.";    echo "Mailer Error: ".$mail->ErrorInfo;// 輸出錯誤資訊}else{    echo ‘Message has been sent.‘;}

4.填好資料,運行一下檔案,就發送成功了。

phpmailer發送郵件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.