By using this function we can send mail from client to destination mail id, it contains four arguments To address, Subject, body and collection of headers.
Number of mail related headers or available user from, CC: (carbon copy), BCC: etc the separate between one header and another header is \r \n. To send mail from our application to destination mail id we need to use SMTP SERVER.
Examples:
- <?php
if(mail(“abc@gmail.com”, “Hi Scott”, “How are you”, “From: Smith@gmail.com”))
echo “Mail Sent”;
else
echo “Not”;
?> - <?php
if(mail(“XYZ@gmail.com”, “Offer Letter”, “Hi. How are you”, “From: HR@184.168.124.59”, _fno_reply: abc@iqschools.com));
echo “sent”;
?> - <?php
$str= <<<abc
Hi <a href= ‘#’> Link </a>
abc;
if(mail(“abc@gmail.com”, “Hi”, $str,”From: Webnoid\r\n(c:Webnoid@gmail.com’)_
echo ‘Sent’
else
echo ‘Not Sent’
?>
<body>
<form method= “post” action= ” “>
<table>
<tr><td> To Address: </td><td><input type =”text” name= “To”></td></tr>
<tr><td> Subject: </td><td><input type= “text”name=”Subj”></td></tr>
<tr><td> Message (or) Body : </td><td><input type= “text” name= “Msg”></td></tr>
<tr><td>From: </td><td><input type= “text” name= “From”</td></tr>
<input type= “submit” value= “Send” name=”sub”>
<?php
if(isset($_POST[‘sub’]))
{
$to= $_POST[‘To’];
$sub= $_POST[‘Subj’];
$body= $_POST[‘Msg’];
$From=$_POST[‘From’];
if(mail($to, $sub, $body, “From: $from”))
{
echo “Mail Sent”;
}
else
echo “Not Sent”;
}
?>
</table>
</form>