X

Rate Us :



Share with Friends :

Menu

PHP-Mail :

By using mail() function, we can send a mail from our application to destination mail id. It contains four arguments : two address, subject, body and collection of headers. mail() function fourth argument is collection of headers, the separator between header and another header is "\r\n". We need to use SMTP server to send the mails from one location to another location.

Example :

<?php if(mail("abc@gmail.com", "Hi", "Hello", "From :xyz")) echo "sent"; else echo "Not sent"; ?>


Different types of mail related headers :

Different types of mail related headers are available like CC(Carbon Copy), BCC(Blank Carbon Copy), content_type etc.

Example 1 :

<?php if(mail("abc@gmail.com", "Hi", "Hello", "From :xyz\r\n CC :Man@gmail.com")) echo "sent"; else echo "Not sent"; ?>

Example 2 :

<?php if(isset($_POST['sub1'])) { $to = $_POST['to']; $sub = $_POST['sub']; $from = $_POST['from']; $body = $_POST['body']; } if(mail($to, $sub, $body, "From :$from")) { echo "Mail sent"; } else { echo "Not sent"; } ?>


<form method = "POST" action = " "> To :<input name = 'to'> <br> Sub :<input name = 'sub'> <br> Body :<input name = 'body'> <br> From :<input name = 'from'> <br> <input type = "submit" name = 'sub1' value = 'click'> </form>

Output :

To : Sub : Body : From :

Example 3 :

<?php if(mail("abc@gmail.com", "HTML email", $str, "From :xyz@gmail.com\r\n Content type :text/html")) { echo "sent"; } else { echo "Not sent"; } ?>


<form method = "POST" action = " "> <br> <span style = 'color :Red'>Username</span> <br> <input type = 'text' name = 't1'> <br> <input type = "submit" name = 'sub' value = 'click'> </form>

Output :

Username