php學習筆記 四 之傳送郵件02 詳細操作

2021-08-25 07:01:11 字數 1403 閱讀 1476

上一節給出了class_smtp.php.乙個很重要的檔案,沒有它,我們是不能傳送郵件的

接下來就利用它來傳送我們輸入的資訊

首先給個文字框

然後寫乙個message_receive_add_email.php

<?php //接收引數 strcontent $strcontent=$http_post_vars["strcontent"]; echo "成功接收引數:strcontent=".$strcontent; //將引數儲存至資料庫 //定義執行sql語句 $sql="insert into db_message.t_message ("; $sql=$sql." intmessageid ,strcontent) "; $sql=$sql." values ( null ,'".$strcontent."' );"; echo "".$sql; //parse error: syntax error, unexpected t_constant_encapsed_string in d:/apache/htdocs/test/message_receive_add.php on line 20 //連線資料庫 $connect=mysql_connect("localhost","root","root") or die("不能連線資料庫伺服器"); //執行資料庫操作,將資料寫入 $query=mysql_db_query("db_message",$sql,$connect) or die("!!!!"); echo "儲存至資料庫:成功!"; //將郵件傳送至郵箱 require("class_smtp.php"); //定義相關引數 $smtpserver="smtp.163.com";//您的smtp伺服器的位址 $port =25; //smtp伺服器的埠,一般是 25 $smtpuser = "您登入smtp伺服器的使用者名稱"; //您登入smtp伺服器的使用者名稱 $smtppwd = "您登入smtp伺服器的密碼"; //您登入smtp伺服器的密碼 $mailtype = "html"; //郵件的型別,可選值是 txt 或 html ,txt 表示是純文字的郵件,html 表示是 html格式的郵件 $sender = "[email protected]"; //發件人,一般要與您登入smtp伺服器的使用者名稱($smtpuser)相同,否則可能會因為smtp伺服器的設定導致傳送失敗 $smtp = new smtp($smtpserver,$port,true,$smtpuser,$smtppwd,$sender); echo ""; $smtp->debug = true; //是否開啟除錯,只在測試程式時使用,正式使用時請將此行注釋 $to = "[email protected]"; //收件人 $subject = "你好"; $body = $strcontent; $send=$smtp->sendmail($to,$sender,$subject,$body,$mailtype); if($send==1)else ?>

傳送結果

PHP之認識PHP 三 解決郵件傳送問題

3 配置php.in。在php.in裡搜尋mail function 1.sendmail from 1715453224qq.com 將郵件配置為自己的郵件 注意去掉 預設為不生效 2.sendmail path d wampserver3.1.7 x64 sendmail sendmail.ex...

PHP學習筆記02 簡單的php指令碼

首先啟動apache和mysql,然後在安裝目錄 xampp htdocs 下新建php檔案並命名為first.php 用文字編輯器開啟php檔案,我用的是dw和sublime text 在php檔案中寫入如下 echo 在 http localhost first.php 上進行檢視,效果如圖 開...

運維筆記之呼叫163郵箱傳送郵件

筆記描述 根據運維需求,自定義指令碼需要郵件告警,此篇文章僅呼叫163郵箱傳送郵箱,並未搭郵件伺服器 一 準備 登陸163郵箱開啟上圖開關 二 伺服器安裝mailx service postfix status 檢視是否開啟,若開啟,service sendmail stop service sen...