The PHP Mail () function is used to send e-mail from a script.
Mail (to,subject,message,headers,parameters);
Parameters |
Description |
To |
Necessary. Specify email recipients. |
Subject |
Necessary. Specify the subject of email. Note: This parameter cannot contain any new line characters. |
Message |
Necessary. Defines the message to be sent. You should use LF (\ n) to separate the rows. |
Headers |
Optional. Specify additional headings, such as from, Cc, and BCC. You should use CRLF (\ r \ n) to separate additional headings. |
Parameters |
Optional. Specify additional parameters for the mail sender. |
Note: PHP requires an installed and running messaging system to make the mail function available. The program used is defined by the configuration settings in the php.ini file.
PHP Simple e-mail
The simplest way to send an email via PHP is to send a text email.
In the following example, we first declare variables ($to, $subject, $message, $from, $headers), and then we use these variables in the mail () function to send an e-mail message:
<?php$to = "[email protected]"; $subject = "Test mail"; $message = "hello! A simple email message. "; $from = "[email protected]"; $headers = "From: $from"; Mail ($to, $subject, $message, $headers); echo "Mail Sent.";? >
PHP Mail Form
With PHP, you can create a feedback form on your site. The following example sends a text message to the specified e-mail address:
email: <input name= ' Email ' type= ' text '/><br/> Subject : <input name= ' Subject ' type= ' text '/> <br/> message:<br/> <textarea name= ' Message ' rows= ' cols= ' > </textarea ><br/> <input type= ' Submit '/> </form> '; }? ></body>