PHP Mail


Mail鍑芥暟鍒楄〃,ezmlm_hash - 璁$畻 EZMLM 鎵闇鐨勬暎鍒楀,mail - 鍙戦侀偖浠

PHP Mail鍑芥暟鍒楄〃
ezmlm_hash - 璁$畻 EZMLM 鎵闇鐨勬暎鍒楀
mail - 鍙戦侀偖浠

浠g爜娉ㄩ噴



濡備綍浣跨敤PHP杩涜閭欢鍙戦併

涓銆丳HP鍐呯疆閭欢鍙戦佸嚱鏁

鍦≒HP涓紝鎻愪緵浜 mail() 鍑芥暟鐢ㄤ簬鍙戦侀偖浠躲備娇鐢ㄨ鍑芥暟闇瑕佽缃偖浠跺ご淇℃伅銆佹敹浠朵汉鍦板潃銆侀偖浠朵富棰樺拰閭欢鍐呭绛夊弬鏁般備笅闈㈡槸涓涓畝鍗曠殑浣跨敤绀轰緥锛

1

2

3

4

5

6

7

8

$to='鏀朵欢浜洪偖绠';

$subject='閭欢涓婚';

$message='閭欢鍐呭';

$from='鍙戜欢浜洪偖绠';

$headers="From: $from". "

" . "Reply-To:$from" . "

" . "X-Mailer: PHP/" . phpversion();

mail($to,$subject,$message,$headers);

鍦ㄤ笂杩颁唬鐮佷腑锛屾垜浠畾涔変簡鏀朵欢浜哄湴鍧銆侀偖浠朵富棰樸侀偖浠跺唴瀹广佸彂浠朵汉閭鍜岄偖浠跺ご淇℃伅銆傞偖浠跺ご淇℃伅瑕佹眰浠ュ瓧绗︿覆褰㈠紡浼犻掞紝浣跨敤
鏉ヨ〃绀烘崲琛屻備娇鐢 mail() 鍑芥暟杩涜閭欢鍙戦佹椂锛岄渶瑕佹湇鍔″櫒鏀寔sendmail鎴朣MTP鍗忚銆傚鏋滄湇鍔″櫒涓嶆敮鎸佽繖涓ょ鍗忚锛宮ail() 鍑芥暟灏嗗け璐ャ傚洜姝わ紝鎴戜滑闇瑕佷娇鐢⊿MTP绫诲簱杩涜閭欢鍙戦併

浜屻佷娇鐢≒HPMailer绫诲簱

PHPMailer鏄竴涓祦琛岀殑PHP閭欢鍙戦佺被搴擄紝瀹冩彁渚涗簡涓板瘜鐨勫姛鑳藉拰鐏垫椿鐨勬帴鍙c備娇鐢≒HPMailer鍙互鏂逛究鍦板彂閫丠TML閭欢銆侀檮浠跺拰甯︽湁璁よ瘉淇℃伅鐨勯偖浠剁瓑銆備笅闈㈡槸涓涓娇鐢≒HPMailer鍙戦侀偖浠剁殑绀轰緥锛

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

usePHPMailerPHPMailerPHPMailer;

usePHPMailerPHPMailerException;

 

require'vendor/autoload.php';

 

// 瀹炰緥鍖朠HPMailer绫

$mail=newPHPMailer(true);

 

try{

    // 鏈嶅姟鍣ㄩ厤缃

    $mail->isSMTP();

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

    $mail->SMTPAuth = true;

    $mail->Username ='浣犵殑Gmail閭';

    $mail->Password ='浣犵殑Gmail閭瀵嗙爜';

    $mail->SMTPSecure ='tls';

    $mail->Port = 587;

 

    // 鏀朵欢浜轰俊鎭

    $mail->setFrom('鍙戜欢浜洪偖绠','鍙戜欢浜哄悕绉');

    $mail->addAddress('鏀朵欢浜洪偖绠','鏀朵欢浜哄悕绉');

 

    // 閭欢鍐呭

    $mail->isHTML(true);

    $mail->Subject ='閭欢涓婚';

    $mail->Body    ='閭欢鍐呭';

 

    // 鍙戦侀偖浠

    $mail->send();

    echo'閭欢鍙戦佹垚鍔燂紒';

}catch(Exception$e) {

    echo'閭欢鍙戦佸け璐: ',$mail->ErrorInfo;

}

鍦ㄤ笂闈㈢殑浠g爜绀轰緥涓紝鎴戜滑棣栧厛浣跨敤 Composer 瀹夎PHPMailer绫诲簱锛屽苟浣跨敤use鍏抽敭瀛楀鍏ュ懡鍚嶇┖闂淬傛帴鐫锛屾垜浠疄渚嬪寲PHPMailer绫伙紝骞惰缃甋MTP鏈嶅姟鍣ㄧ殑鐩稿叧閰嶇疆銆佹敹浠朵汉鍦板潃銆侀偖浠朵富棰樺拰閭欢鍐呭绛変俊鎭傛渶鍚庯紝璋冪敤send()鏂规硶鍙戦侀偖浠躲

鎬讳箣锛屽湪PHP涓疄鐜伴偖浠跺彂閫佷笉闇瑕佸お澶氱殑浠g爜锛屾垜浠彧闇瑕侀夋嫨閫傚綋鐨勬柟寮忓苟璁剧疆濂界浉鍏冲弬鏁板嵆鍙傝皟鐢ㄩ偖浠跺彂閫佸嚱鏁版椂锛岄渶瑕佹敞鎰忛夋嫨鍚堥傜殑閭欢鍙戦佹柟寮忎互鍙婅缃ソ鐩稿叧鐨勯偖浠跺ご淇℃伅銆傚敖绠′娇鐢≒HPMailer绫诲簱闇瑕佸紩鍏ユ洿澶氱殑浠g爜锛屼絾鏄畠鎻愪緵浜嗘洿涓板瘜鐨勫姛鑳藉拰鏇寸伒娲荤殑鎺ュ彛锛屽悓鏃惰繕鍙互鏇存柟渚垮湴澶勭悊寮傚父鎯呭喌銆傜浉淇″湪瀹為檯寮鍙戜腑锛岃鑰呬滑鍙互鏍规嵁瀹為檯闇瑕侀夋嫨鍚堥傜殑鏂瑰紡瀹炵幇閭欢鍙戦佸姛鑳姐

浠ヤ笂灏辨槸濡備綍浣跨敤PHP杩涜閭欢鍙戦佺殑璇︾粏鍐呭锛屾洿澶氳鍏虫敞php涓枃缃戝叾瀹冪浉鍏虫枃绔狅紒




浠ヤ笂灏辨槸PHP Mail鍑芥暟鍒楄〃鐨勮缁嗗唴瀹癸紝鏇村淇℃伅璇峰叧娉∣D浜戝叾瀹冪浉鍏虫枃绔狅紒



鏈枃URL锛http://www.odweb.cn/news_show.html?id=122