PHP發郵件函數實現代碼

來源:互聯網
上載者:User

不需要郵件伺服器,不使用mail內建函數,一個類就搞定,利用php教程mailer類我寫了一個自訂函數 sendmail() ,very實用!

以前也在幾個php論壇上發表過這個發郵件的函數,今天再發,因為today要附上使用例子,如果你還不會用,那就要補補php基礎課了。

  1.準備檔案 sendmail.class.php檔案、phpmailer類     下載  

2.下載後,解壓 phpmailer.rar 到伺服器的任何目錄下

3.開啟 sendmail.class.php ,修改如下(淺黃色部分是必須 要修改的變數值)

 // 以下 5 個變數值必須據實修改
 $host     = '61.183.41.172';
 $username = 'admin@php95.com';
 $password = "******"     
 $from     = 'admin@php95.com';   
 $fromname = '天馬部落格';  

// 先設定 $to $subject $content 這三個變數的值,再調用 sendmail 函數來發送郵件
$to = 'nt2030@qq.com';
$subject = '測試phpmailer類發送郵件';
$content = '測試phpmailer類發送郵件';
sendmail($to,$subject,$content);

4.修改 sendmail.class.php 完畢後,運行它..

你的郵件是否發送成功?

天馬測試本代碼,is ok,見證:

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.