PHP °²È«µÄµç×ÓÓʼþ
ÔÚÉÏÒ»½ÚÖÐµÄ PHP e-mail ½Å±¾ÖУ¬´æÔÚ×ÅÒ»¸ö©¶´¡£
PHP E-mail ×¢Èë
Ê×ÏÈ£¬Çë¿´ÉÏÒ»½ÚÖÐµÄ PHP ´úÂ룺
<html> <body> <?php if (isset($_REQUEST['email'])) //if "email" is filled out, send email { //send email $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail("someone@example.com", "Subject: $subject", $message, "From: $email" ); echo "Thank you for using our mail form"; } else //if "email" is not filled out, display the form { echo "<form method='post' action='mailform.php'> Email: <input name='email' type='text' /><br /> Subject: <input name='subject' type='text' /><br /> Message:<br /> <textarea name='message' rows='15' cols='40'> </textarea><br /> <input type='submit' /> </form>"; } ?> </body> </html>
ÒÔÉÏ´úÂë´æÔÚµÄÎÊÌâÊÇ£¬Î´¾ÊÚȨµÄÓû§¿Éͨ¹ýÊäÈë±íµ¥ÔÚÓʼþÍ·²¿²åÈëÊý¾Ý¡£
¼ÙÈçÓû§ÔÚ±íµ¥ÖеÄÊäÈë¿òÄÚ¼ÓÈëÕâЩÎı¾£¬»á³öÏÖʲôÇé¿öÄØ£¿
someone@example.com%0ACc:person2@example.com %0ABcc:person3@example.com,person3@example.com, anotherperson4@example.com,person5@example.com %0ABTo:person6@example.com
ÓëÍù³£Ò»Ñù£¬mail() º¯Êý°ÑÉÏÃæµÄÎı¾·ÅÈëÓʼþÍ·²¿£¬ÄÇôÏÖÔÚÍ·²¿ÓÐÁ˶îÍâµÄ Cc:, Bcc: ÒÔ¼° To: ×ֶΡ£µ±Óû§µã»÷Ìá½»°´Å¥Ê±£¬Õâ·â e-mail »á±»·¢Ë͵½ÉÏÃæËùÓеĵØÖ·£¡
PHP ·ÀÖ¹ E-mail ×¢Èë
·ÀÖ¹ e-mail ×¢ÈëµÄ×îºÃ·½·¨ÊǶÔÊäÈë½øÐÐÑéÖ¤¡£
ÏÂÃæµÄ´úÂëÓëÉÏÒ»½ÚÀàËÆ£¬²»¹ýÎÒÃÇÒѾÔö¼ÓÁ˼ì²â±íµ¥ÖÐ email ×ֶεÄÊäÈëÑéÖ¤³ÌÐò£º
<html> <body> <?php function spamcheck($field) { //filter_var() sanitizes the e-mail //address using FILTER_SANITIZE_EMAIL $field=filter_var($field,FILTER_SANITIZE_EMAIL
); //filter_var() validates the e-mail //address using FILTER_VALIDATE_EMAIL if(filter_var($field,FILTER_VALIDATE_EMAIL
)) { return TRUE; } else { return FALSE; } } if (isset($_REQUEST['email'])) {//if "email" is filled out, proceed //check if the email address is invalid $mailcheck = spamcheck($_REQUEST['email']); if ($mailcheck==FALSE) { echo "Invalid input"; } else {//send email $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail("someone@example.com", "Subject: $subject", $message, "From: $email" ); echo "Thank you for using our mail form"; } } else {//if "email" is not filled out, display the form echo "<form method='post' action='mailform.php'> Email: <input name='email' type='text' /><br /> Subject: <input name='subject' type='text' /><br /> Message:<br /> <textarea name='message' rows='15' cols='40'> </textarea><br /> <input type='submit' /> </form>"; } ?> </body> </html>
ÔÚÉÏÃæµÄ´úÂëÖУ¬ÎÒÃÇʹÓÃÁË PHP ¹ýÂËÆ÷À´¶ÔÊäÈë½øÐÐÑéÖ¤£º
- FILTER_SANITIZE_EMAIL ´Ó×Ö·û´®ÖÐɾ³ýµç×ÓÓʼþµÄ·Ç·¨×Ö·û
- FILTER_VALIDATE_EMAIL ÑéÖ¤µç×ÓÓʼþµØÖ·
Äú¿ÉÒÔÔÚÎÒÃÇµÄ PHP ¹ýÂËÆ÷ÕâÒ»½ÚÖÐÔĶÁ¸ü¶àÓйعýÂËÆ÷µÄÄÚÈÝ¡£