PHP allows you to send emails directly from scripts.
PHP mail() function is used to send emails from scripts.
mail(to,subject,message,headers,parameters)
Parameter | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
to | Required. Specify email recipients. | ||||||||||||
subject | Required. Specifies the subject of the email. Note: This parameter cannot contain any newline characters. | ||||||||||||
message | Required. Define the message to be sent. LF (n) should be used to separate lines. | ||||||||||||
headers |
Additional headers should be separated using CRLF (rn). |
||||||||||||
parameters | Optional. Specifies additional parameters for the mailer. |
PHP Simple E-Mail
The easiest way to send an email via PHP is to send a text email.
<?<span>php </span><span>//</span><span> 何问起 hovertree.com</span> <span>$to</span> = "hello@hovertree.net"<span>; </span><span>$subject</span> = "Test mail"<span>; </span><span>$message</span> = "Hello! This is a simple email message."<span>; </span><span>$from</span> = "hello@hovertree.net"<span>; </span><span>$headers</span> = "From: <span>$from</span>"<span>; </span><span>mail</span>(<span>$to</span>,<span>$subject</span>,<span>$message</span>,<span>$headers</span><span>); </span><span>echo</span> "Mail Sent."<span>; </span>?>
In the following example, we first declare the variables ($to, $subject, $message, $from, $headers), and then we use these variables in the mail() function to send an e-mail:
PHP Mail Form
<html> <body> <!-- 何问起 hovertree.com --> <?<span>php </span><span>if</span> (<span>isset</span>(<span>$_REQUEST</span>['email'<span>])) </span><span>//</span><span>if "email" is filled out, send email</span> <span> { </span><span>//</span><span>send email</span> <span>$email</span> = <span>$_REQUEST</span>['email'<span>] ; </span><span>$subject</span> = <span>$_REQUEST</span>['subject'<span>] ; </span><span>$message</span> = <span>$_REQUEST</span>['message'<span>] ; </span><span>mail</span>( "someone@example.com", "Subject: <span>$subject</span>", <span>$message</span>, "From: <span>$email</span>"<span> ); </span><span>echo</span> "Thank you for using our mail form"<span>; } </span><span>else</span> <span>//</span><span>if "email" is not filled out, display the form</span> <span> { </span><span>echo</span> "<span><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></span>"<span>; } </span>?> </body> </html>
With PHP, you can create a feedback form on your site. The following example sends a text message to the specified e-mail address:
Explanation of examples:
1) Windows needs to configure the SMTP of IIS; Linux comes with the sendmail component, no setting is required, and it directly supports the mail function sending function
2) Declare various SMTP parameters in php.ini
3) Use of mail("receiving address", "email subject", "email content") function
Example 1: Configuring local SMTP server
Step one: php.ini settings:
SMTP = localhost
smtp_port = 25
Step two: You need to install the SMTP that comes with IIS. Right-click on the SMTP virtual server and make the following settings in the pop-up properties window:
Click the "Access" tab, then click "Relay", click "Add" in the pop-up window, and then select "Single Server" Computer", add the IP address as "127.0.0.1", then
The way back is confirmed.
Step 3:
Recommended: http://www.cnblogs.com/roucheng/p/3528396.html
PHP mail, phpmail PHP allows you to send emails directly from scripts. PHP mail() function The PHP mail() function is used to send emails from scripts. Syntax mail(to,subject,message,heade...