PHPMailer IIS下的PHP指令碼使用GMAIL發送郵件PHP

來源:互聯網
上載者:User

簡介:這是PHPMailer IIS下的PHP指令碼使用GMAIL發送郵件PHP的詳細頁面,介紹了和php,有關的知識、技巧、經驗,和一些php源碼等。

class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=325742' scrolling='no'>
PHPMailer IIS下的PHP指令碼使用GMAIL發送郵件PHP

在windows搭建PHP環境,配置比較麻煩,所以一般採用別人封裝好的PHP組件,明晨網路MingchenNet.com使用的是phpnow。

    明晨網路MingchenNet.com使用GOOGLE強力驅動的企業郵局標準版。google使用了安全的ssl加密的smtp協議,所以在php下串連GMAIL時,需要做一番設定,使其支援ssl。這裡給出明晨網路MingchenNet.com的測試結論。

    使用iProber.php探針查看PHP環境,phpnow預設安裝是不支援Socket的,如果串連普通的smtp伺服器沒有問題,串連ssl加密的smtp伺服器就提示:SMTP Error:Could not connect to SMTP host 。這需要開啟php的socket和openssl組件,通過修改PHP.INI設定檔來實現。phpnow的設定檔PHP.INI位於c:\windows目錄下,而非c:\programe files\php_iis下!

首先,開啟c:\windows\php.ini檔案,去掉下面兩行前的分號,然後儲存。

;extension=php_sockets.dll

;extension=php_openssl.dll

然後,複製C:\Program Files\php_iis\php\libeay32.dll 和ssleay32.dll到c:\windows\system32目錄下,重啟IIS。

ok,使用phpmailer測試你的gmail吧。

1.

<?php

2.

include("class.phpmailer.php");//載入phpmailer主類,一般情況下要設定好phpmailer路徑

3.

include("class.smtp.php"); // 載入smtp類,一般情況下要設定好phpmailer路徑

4.

$mail  = new PHPMailer();

5.

$mail->IsSMTP(); // 使用SMTP

6.

$mail->SMTPSecure = "ssl";

7.

$mail->Host = "smtp.gmail.com";

8.

$mail->Port = 465;                   // GMAIL的SMTP連接埠號碼

9.

$mail->SMTPAuth = true; // 開啟SMTP認證

10.

$mail->Username = "mingchennet@gmail.com"; // GMAIL使用者名稱

11.

$mail->Password = "password"; // GMAIL密碼

12.

$webmaster_email = "mingchennet@gmail.com"; //回複到該地址

13.

$email="mingchennet@gmail.com"; // 收件者

14.

$name="明晨網路"; // 收件者名稱

15.

$mail->From = $webmaster_email;

16.

$mail->FromName = "明晨網路";

17.

$mail->AddAddress($email,$name);

18.

$mail->AddReplyTo($webmaster_email,"明晨網路");

19.

$mail->WordWrap = 50; // 設定 word wrap

20.

//$mail->AddAttachment("/var/tmp/file.tar.gz"); // 附件1

21.

//$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // 附件2

22.

$mail->IsHTML(true); // 以HTML發送

23.

$mail->Subject = "This is the subject";

24.

$mail->Body = "Hi,

25.

This is the HTML BODY "; //HTML Body

26.

$mail->AltBody = "This is the body when user views in plain text format"; //純文字時的Body

27.

if(!$mail->Send())

28.

{

29.

echo "Mailer Error: " . $mail->ErrorInfo;

30.

}

31.

else

32.

{

33.

echo "Message has been sent";

34.

}

35.

?>

“PHPMailer IIS下的PHP指令碼使用GMAIL發送郵件PHP”的更多相關文章 》

愛J2EE關注Java邁克爾傑克遜視頻站JSON線上工具

http://biancheng.dnbcw.info/php/325742.html pageNo:13

聯繫我們

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