PHP Send Mail
In web application, it is common to send email messages. Almost every website has some query form or contact form where user fill form & form data will be sent in email to site administrator.
PHP provides built-in mail() function to send emails. You can add sender, recipients & subject as per your choice using mail() function parameters.
Basic Syntax PHP mail()
Function:
<?php
mail(to, subject, message, headers, parameters);
?>
PHP mail()
parameters
Parameter | Description |
to | Required. It is used to specifies the receivers/recipients of the email. |
subject | Required. It specifies the subject of the email. |
message | Required. It is used to specify main email message. |
headers | Optional. It is used to specifies additional headers, such as From, Cc, and Bcc. |
parameters | Optional. It is used to specifies an additional parameter for sendmail program |
Complete Example of PHP mail()
function:
<?php
$to = "testmail@gmail.com";
$subject = "Tutorias Class Test Mail";
$txt = "Hello Tutorials Class! This is test message";
$headers = "From: youremail@gmail.com" . "\r\n" .
"CC: anotheremail@gmail.com";
mail($to,$subject,$txt,$headers);
?>
Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments |
---|
No Content Found. |
Interview Questions & Answers |
---|
No Content Found. |