
PHP Mail Function | PHP Send Mail With Attachment
The mail sending process has become a commonly used process for any website, it may be used for the contact form or newsletter or a shopping purpose mail generated and sent from the website or system it may be through a crone job also. So PHP Mail Function provides us the functionality to send mail in a properly organized way. In this post, we are going to see How to Send Mail With and without Attachment in PHP.
The function name is mail(); to send mail through PHP.
Parameters should pass through the PHP mail function
There are 5 numbers parameters should be sent through the PHP mail function and they are 1. to, 2. subject, 3. message, 4. headers, and 5. parameters among them 3 are required and they are 1. to, 2. subject, 3. message and we general use 4 parameters and that is the 4. header with the 3 required parameters,
- 1. to The to is Required. it is the receivers of the email
- 2. subject: The subject is Required. It’s the subject of the email. and cannot contain any newline characters
- 3. message: The message is also Required. its the message to be sent. Each line should be separated with an LF (\n). Lines should not exceed 70 characters.
- 4. headers: The headers are Optional. It specifies additional headers, like From, Cc, and Bcc. etc The additional headers should be separated with a CRLF (\r\n).
- 5. parameters: The parameters are also Optional. Specifies an additional parameter. ie, this can be used to set the envelope sender address when using send a mail with the -f send mail option
Example of PHP Normal Mail Sending
' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
mail($to,$subject,$message,$headers);
?>
Example of PHP HTML Mail Sending
HTML email This email contains HTML Tags!
Firstname | Lastname |
---|---|
John | Doe |