使用phpmailer發送郵件

來源:互聯網
上載者:User

標籤:

先下載相應的php檔案:http://files.cnblogs.com/files/tianguook/phpmailer.rar

解壓後有2個php檔案(2個類)  1個html檔案(API)

將2個php檔案放到php項目中

簡述:我這裡是用一個163的郵箱發訊息給126的郵箱

關鍵代碼如下:

<?php        require ‘class.phpmailer.php‘;        $mail = new PHPMailer(true); //建立郵件發送類        $mail->CharSet = "UTF-8";//設定資訊的編碼類別型        $address = "******@126.com";//收件者地址        $mail->IsSMTP(); // 使用SMTP方式發送        $mail->Host = "smtp.163.com"; //使用163郵箱伺服器        $mail->SMTPAuth = true; // 啟用SMTP驗證功能        $mail->Username = "******@163.com"; //你的163伺服器郵箱帳號        $mail->Password = "******"; // 163郵箱密碼        $mail->Port = 25;//郵箱伺服器連接埠號碼        $mail->From = "******@163.com"; //郵件寄件者email地址        $mail->FromName = "測試郵件";//寄件者名稱        $mail->AddAddress("$address", "張三"); //收件者地址,可以替換成任何想要內送郵件的email信箱,格式是AddAddress("收件者email","收件者姓名")        $mail->AddAttachment("D:\abc.txt"); // 添加附件(注意:路徑不能有中文)        $mail->IsHTML(true);//是否使用HTML格式        $mail->Subject = "測試測試"; //郵件標題        $mail->Body = "新年快樂"; //郵件內容,上面設定HTML,則可以是HTML        if (!$mail->Send()) {            echo "郵件發送失敗. <p>";            echo "錯誤原因: " . $mail->ErrorInfo;            exit;        }?>

 

使用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.