w3pop.com :: ÍøÂçѧԺ :: PHP :: PHP ·¢ËÍÓʼþ
PHP allows you to send e-mails directly from a script.
PHPÔÊÐíÄãͨ¹ý½Å±¾Ö±½Ó·¢ËÍe-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²ÎÊý¡£
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"; ?> |
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> <?php </body> |
This is how the example above works:
ÏÂÃæÎÒÃǾßÌåµÄ½²Ò»ÏÂÉÏÊö´úÂëµÄ¹¤×÷ÔÀí£º
For more information about the PHP mail() function, visit our PHP Mail Reference.
Èç¹ûÄãÏëÁ˽â¸ü¶à¹ØÓÚPHP mail()º¯Êý£¬Çë·ÃÎÊÎÒÃǵÄPHP Mail ²ÎÊý¡£
ÆÀÂÛ (0)
All