注意,由于ae_send_mail函數(shù)使用php內(nèi)置的mail()函數(shù)來(lái)發(fā)送郵件,與此函數(shù)相關(guān)的問(wèn)題,ae_send_mail也會(huì)存在。\n大家在使用時(shí),遇到問(wèn)題時(shí),請(qǐng)參考mail函數(shù)的用法及相關(guān)解釋。<\/p>\n<\/td><\/tr><\/table>\n\n\n\n
在php中,使用自帶的mail()函數(shù)來(lái)發(fā)送郵件,會(huì)存在很多不安全因素。 我們實(shí)現(xiàn)了如下的ae_send_mail函數(shù),適用于PHP4.0.2或更高版本。 ae_send_mail調(diào)用時(shí)只用四個(gè)參數(shù):發(fā)件人,收件人,主題,郵件內(nèi)容。
此函數(shù)通過(guò)加過(guò)一些過(guò)濾機(jī)制,可以去除一切不必要的特殊字符對(duì)郵件的影響。
代碼:
<?php /** * Email郵件發(fā)送 * by bbs.it-home.org */ function ae_send_mail($from, $to, $subject, $text, $headers="") { if (strtolower(substr(PHP_OS, 0, 3)) === 'win') $mail_sep = "\r\n"; else $mail_sep = "\n"; function _rsc($s) { $s = str_replace("\n", '', $s); $s = str_replace("\r", '', $s); return $s; } $h = ''; if (is_array($headers)) { foreach($headers as $k=>$v) $h = _rsc($k).': '._rsc($v).$mail_sep; if ($h != '') { $h = substr($h, 0, strlen($h) - strlen($mail_sep)); $h = $mail_sep.$h; } } $from = _rsc($from); $to = _rsc($to); $subject = _rsc($subject); mail($to, $subject, $text, 'From: '.$from.$h); } ?>
以上函數(shù)有必選參數(shù):$from, $to, $subject, $text,另外有一個(gè)可選參數(shù)$headers,用于傳輸一些郵件頭信息,它可以接受數(shù)組的形式,例如:(“頭信息1”=>“值”,“頭信息2”=>“值”)。
以下是在具體頁(yè)面中的例子,大家可以參考下。
<?php /** * as_send_mail函數(shù)示例 * 接收聯(lián)系人信息 * by bbs.it-home.org */ $site_admin = 'your@email.adress'; // function ae_send_mail (see code above) is pasted here if (($_SERVER['REQUEST_METHOD'] == 'POST') && isset($_POST['subject']) && isset($_POST['text']) && isset($_POST['from1']) && isset($_POST['from2'])) { $from = $_POST['from1'].' <'.$_POST['from2'].'>'; // nice RFC 2822 From field ae_send_mail($from, $site_admin, $_POST['subject'], $_POST['text'], array('X-Mailer'=>'PHP script at '.$_SERVER['HTTP_HOST'])); $mail_send = true; } ?> <html><head> <title>發(fā)送郵件的例子</title> </head> <body> <?php if (isset($mail_send)) { echo '<h1>郵件已發(fā)送!謝謝!</h1>'; } else { ?> <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post"> 姓名: <input type="text" name="from1" size="30" /><br /> 郵箱: <input type="text" name="from2" size="30" /><br /> 主題: <input type="text" name="subject" size="30" /><br /> 內(nèi)容: <br /> <textarea rows="5" cols="40" name="text"></textarea> <input type="submit" value="send" /> </form> <?php } ?> </body> </html>
注意,由于ae_send_mail函數(shù)使用php內(nèi)置的mail()函數(shù)來(lái)發(fā)送郵件,與此函數(shù)相關(guān)的問(wèn)題,ae_send_mail也會(huì)存在。 大家在使用時(shí),遇到問(wèn)題時(shí),請(qǐng)參考mail函數(shù)的用法及相關(guān)解釋。
??? ???? ??
???? ?? ??? ??? ?? AI ?? ?
???? ?? ???? ??? AI ?????.
AI ? ???
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!
???? ?? ?? ?? ???
??? ??, ???? ?? ????.
??? PHP ?? ?? ??
??? ? ?? ??
? ??? ?? ?? ?????(SublimeText3)
PHP ?? ??? ?? ???? ?? ? ????? ??? ?????. 1. ?? ??? ??? ??? ??? ? ? ??? ??? ??? ?? ?? ??? ???? ???????. 2. ?? ??? ???? ???? ? ?? ????? ?? ?? ?? ??? ?????. 3. $ _get ? $ _post? ?? Hyperglobal ??? ?? ???? ?? ??? ? ??? ??? ??????? ???????. 4. ?? ?? ?? ???? ?? ?? ?? ??? ?????? ?? ??? ??? ?? ??? ???????. ??? ??? ????? ??? ??? ?? ???? ????? ? ??? ? ? ????.
PHP ?? ???? ???? ????? ?? ? ??? ???? ?? ?? ? ??? ???? ?? ??? ?????? ??? ??? ? ? ???????. 1. ??? ?? CSRF? ???? ?? ??? ??? ???? ?????? ??? ???? FINFO_FILE? ?? ?? MIME ??? ?????. 2. ??? ??? ??? ???? ??? ?? ??? ?? ? WEB ????? ??? ???? ??????. 3. PHP ?? ??? ?? ? ?? ???? NGINX/APACHE? ??? ????? ?? ???? ?????. 4. GD ?????? ??? ? ?? ???? ??? ?? ??? ?? ????.
PHP ?? ???? ? ?? ???? ??? ????. 1. // ?? #? ???? ? ?? ??? ???? // ???? ?? ????. 2. ?? /.../ ?? ?? ?? ??? ????? ?? ? ?? ??? ?? ? ? ????. 3. ?? ?? ?? / if () {} /? ?? ?? ??? ????? ??? ?? ?? ?? ??? ???? ????? ???? ??? ?? ???? ???? ??? ? ??? ??????.
Ageneratorinphpisamemory- ???? Way-Erate-Overgedatasetsetsbaluesoneatimeatimeatimeatimallatonce.1.generatorsuseTheyieldKeywordTocroadtOpvaluesondemand, RetingMemoryUsage.2
PHP ??? ???? ??? ??? ??? ????? ????. ??? ????? ?? ???? ??? "?? ? ?"??? "?"? ???????. 1. ??? ? ??? ??? DocBlock (/*/)? ?? ?? ??? ???? ??? ? ?? ???? ??????. 2. JS ??? ???? ?? ???? ??? ?? ??? ??? ?????. 3. ??? ?? ?? ?? ??? ???? ????? ????? ???? ?? ????? ???? ? ??????. 4. Todo ? Fixme? ????? ???? ? ? ??? ??? ???? ?? ?? ? ??? ???????. ??? ???? ?? ??? ??? ?? ?? ?? ???? ???? ? ????.
tolearnpheffectical, startBysetTupaloCalserErverEnmentUsingToolslikexamppandacodeeditor -likevscode.1) installxamppforapache, mysql, andphp.2) useacodeeditorforsyntaxsupport.3)) 3) testimplephpfile.next, withpluclucincludechlucincluclucludechluclucled
toinstallphpquickly, usexampponwindowsorhomebrewonmacos.1. ??, downloadandinstallxAmpp, selectComponents, startApache ? placefilesinhtdocs.2
PHP??? ???? ??? ?? ?? ????? ???? ??? ?? ??? ??? ?? ? ??? ??? ???? ?????. ???? 0?? ???? ?? ??? ???? ? ?? ???? ?? ?? ? ? ????. MB_SUBSTR? ?? ??? ??? ???????. ? : $ str = "hello"; echo $ str [0]; ?? H; ??? MB_SUBSTR ($ str, 1,1)? ?? ??? ??? ??? ??????. ?? ???????? ???? ??? ???? ?? ???? ?? ?? ???? ?????? ??? ????? ?? ??? ?? ??? ???? ???? ?? ????.