ÍøÂçѧԺ w3popÉçÇø ÍøÂç×ÊÔ´ ITÐÂÎÅ

w3pop.com :: ÍøÂçѧԺ :: PHP :: PHP ·¢ËÍÓʼþ

»áÔ±µÇ½

ÕʺÅ

ÃÜÂë

»Ø´ð

¼ÇסÃÜÂë

Íü¼ÇÃÜÂë? ×¢²á

PHP
PHP Libxml
PHP Math
PHP Misc
PHP MySQL
PHP SimpleXML
PHP String
PHP XML
PHP Zip
PHP Mail
ÓÃPHP5µÄDirector..
PHP ×èÖ¹SQL×¢ÈëÊ..
PHP5ÃæÏò¶ÔÏó - »..
PHP5ÃæÏò¶ÔÏó - »..
PHP5ÃæÏò¶ÔÏó - »..
PHP5ÃæÏò¶ÔÏó - »..
PHP5ÃæÏò¶ÔÏó - »..
php5ÃæÏò¶ÔÏó - »..
php5ÃæÏò¶ÔÏó - »..
ÓÃPHP¿ØÖÆÓû§µÄä..
PHP PDO ѧϰ±Ê¼Ç

PHP ·¢ËÍÓʼþ


×÷Õß:w3pop.com ·­Òë/ÕûÀí:w3pop.com ·¢²¼:2007-04-28 ÐÞ¸Ä:2007-06-17 ä¯ÀÀ:8623 :: ::

PHP allows you to send e-mails directly from a script.
PHPÔÊÐíÄãͨ¹ý½Å±¾Ö±½Ó·¢ËÍe-mail¡£


The PHP mail() Function
PHP mail()º¯Êý

The PHP mail() function is used to send emails from inside a script.
PHP mail()º¯Êý¿ÉÒԴӽű¾ÄÚ·¢ËÍemail¡£

Syntax
Óï·¨

mail(to,subject,message,headers,parameters)

 

Parameter
²ÎÊý
Description
ÃèÊö
to Required. Specifies the receiver / receivers of the email
±ØÒª²ÎÊý¡£Ö¸¶¨emailµÄ½ÓÊÕÕß
subject Required. Specifies the subject of the email. Note: This parameter cannot contain any newline characters
±ØÒª²ÎÊý¡£Ö¸³öemailµÄÖ÷Ìâ¡£×¢Ò⣺Õâ¸ö²ÎÊý°üº¬µÄ×Ö·û²»ÄÜ»»ÐУ¨Ö»ÄÜÏÔʾһÐУ©
message Required. Defines the message to be sent. Each line should be separated with a LF (n). Lines should not exceed 70 characters
±ØÒª²ÎÊý¡£¶¨Òå·¢Ë͵ÄÐÅÏ¢¡£Ã¿Ðж¼±ØÐëÓã¨n£©·Ö¸ô¿ª¡£Ã¿Ðв»Äܳ¬¹ý70¸ö×Ö·û
headers Optional. Specifies additional headers, like From, Cc, and Bcc. The additional headers should be separated with a CRLF (rn)
¿ÉÑ¡²ÎÊý¡£Ö¸¶¨¸½¼Ó±êÌ⣬È磺form¡¢Cc¼°Bcc¡£¸½¼Ó±êÌâͨ¹ý£¨rn£©½øÐзָô
parameters Optional. Specifies an additional parameter to the sendmail program
¿ÉÑ¡²ÎÊý¡£¸øsendmail³ÌÐòÖ¸¶¨Ò»¸ö¸½¼Ó²ÎÊý

Note: For the mail functions to be available, PHP requires an installed and working email system. The program to be used is defined by the configuration settings in the php.ini file. Read more in our PHP Mail reference.
×¢Ò⣺PHPÐèÒª°²×°¡¢ÔËÐÐemailϵͳ²Å¿ÉÒÔʹÓÃmailº¯Êý¡£ËùʹÓõijÌÐòÊÇͨ¹ýphp.iniÎļþÖеÄÅäÖÃÊôÐÔÀ´È·¶¨µÄ¡£ÔĶÁ¸ü¶àµÄ¹ØÓÚPHP Mail²ÎÊý¡£


PHP Simple E-Mail
¼òÒ×µÄE-mail

The simplest way to send an email with PHP is to send a text email.
ʹÓÃPHP·¢ËÍÓʼþµÄ×î¼òµ¥µÄ·½·¨¾ÍÊÇ·¢ËÍÒ»¸öÎı¾¸ñʽµÄemail¡£

In the example below we first declare the variables ($to, $subject, $message, $from, $headers), then we use the variables in the mail() function to send an e-mail:
ÔÚÏÂÃæµÄ°¸Àýµ±ÖУ¬ÎÒÃÇÊ×ÏÈÉùÃ÷±äÁ¿($to, $subject, $message, $from, $headers)¡£½ÓÏÂÀ´ÎÒÃÇʹÓÃmail()º¯ÊýÖеıäÁ¿À´·¢ËÍÒ»·âe-mail£º

<?php
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

 


PHP Mail Form
PHP Óʼþ[mail]¸ñʽ

With PHP, you can create a feedback-form on your website. The example below sends a text message to a specified e-mail address:
Äã¿ÉÒÔʹÓÃPHPÔÚÄãµÄÍøÕ¾ÉϽ¨Á¢Ò»¸ö·´À¡±íµ¥[feedback-form]¡£ÎÒÃǽ«Í¨¹ýÏÂÃæµÄ°¸Àý½ÌÄãÈçºÎÏòÒ»¸öÖ¸¶¨µÄe-mailµØÖ··¢ËÍÎı¾Óʼþ£º

<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>


This is how the example above works:
ÏÂÃæÎÒÃǾßÌåµÄ½²Ò»ÏÂÉÏÊö´úÂëµÄ¹¤×÷Ô­Àí£º

  • First, check if the email input field is filled out
    Ê×ÏÈ£¬¼ì²éemailÊäÈë¿òÊÇ·ñÒѱ»Ìî³äÐÅÏ¢
  • If it is not set (like when the page is first visited); output the HTML form
    Èç¹ûûÓÐÌî³äÐÅÏ¢£¨±ÈÈ磺µÚÒ»´Î·ÃÎÊÒ³Ãæ£©£»Êä³öHTML±íµ¥
  • If it is set (after the form is filled out); send the email from the form
    Èç¹ûÒÑÌî³äÐÅÏ¢£¨±íµ«Òѱ»Ìîд£©£»Ôò·¢ËÍ±íµ¥ÖеÄemail
  • When submit is pressed after the form is filled out, the page reloads, sees that the email input is set, and sends the email
    µ±±íµ¥ÌîдÍê±Ï£¬È·ÈÏÌá½»Ö®ºó£¬Ò³Ã潫±»ÖØÐÂ×°ÔØ£»´Ëʱ£¬Äã¿ÉÒÔ¿´¼ûemailÉèÖÃÍê±Ï£¬²¢±»·¢ËͳöÈ¥

PHP Mail Reference
PHP Óʼþ[mail]²ÎÊý

For more information about the PHP mail() function, visit our PHP Mail Reference.
Èç¹ûÄãÏëÁ˽â¸ü¶à¹ØÓÚPHP mail()º¯Êý£¬Çë·ÃÎÊÎÒÃǵÄPHP Mail ²ÎÊý¡£

ÆÀÂÛ (0) All