Home | Add to Favorites | Ebooks Directory | News  
PHP  Script programming
Home
PHP  Article
PHP Tutorial 
PHP Script  Download
Books
PHP Manual
PHP Resource
PHP Tutorial

2. Mail as text using mail() function
   -----------------------------------------------------
   
   For sending mail using PHP 's mail() function as a plain text , simple header manipulation is sufficient    containing from, to emailids and content-type with no mime - boundary


 

  The parameters to be used in the header are as follows
   1.From (sender E-mail Id)
   2.Return-Path (Receiver's E-mail Id)
   3.Content-Type with charset=US-ASCII option (the content type is plain text here since this application aims at sending text as mail)
   4.The X-Mailer option is optional (any name can be given if this opion is used)
   if the mail has been successfully sent then the mail() function returns 1 else 0


Failure of mail may be due incorrect header, invalid (in terms of syntax)from id and To ids,thereby a javascript email validation is not essential in this application
   However this does not detect Mailer daemon
    <?php
    if($_POST)
    {  
                      $Email=$_POST['to_id'];
                   $Mail=$_POST['from_id'];
                   $Name=$_POST['name'];
                   $Mailbody=$_POST['msg_body'];
                   $subject=$_POST['subject'];
                   $Mailheaders= "From: $Name <{$Mail}>\r\n"
                                           . "Return-Path: {$Mail}\r\n"
                                           . "Content-Type: text/plain;charset=US-ASCII\r\n"
                                           . "X-Mailer: SOMe name" . VERSION;
   
                                           $ok=mail ("$Email","$subject",$Mailbody, $Mailheaders);
   if($ok!=1)
           echo "<font face='arial' size='4' color='red'><b>Check for Valid e-mail Id!</b></font>";
   else
           echo "<font face=arial size=3 color=red>Mail has been sent to</font><br><font color=green size=2><b>$to_id</b></font>";
   ?>
           
   <form name="frm_mail" method="post">
           <table border="0" cellspacing="0" cellpadding="0">
                   <tr>
                           <td>
                            <font face="arial" color="red" size="4"><b>Email the Experts</b></font>
                           </td>
                   </tr>
                   <tr><td> </td></tr>
                   <tr>
                           <td>
                                   From:
                           </td>
                           <td>
                                   <input type="text" name="from_id" size=30>
                           </td>
                   </tr>
                   <tr><td> </td></tr>
                   <tr>
                           <td>
                                   To:
                           </td>
                           <td>
                                   <input type="text" name="to_id" size=30>
                           </td>
                   </tr>
 

                   <tr><td> </td></tr>
                   <tr>
                           <td>
                                   Subject:
                           </td>
                           <td>
                                   <input type="text" name="subject" size=30>
                           </td>
                   </tr>
                   <tr><td> </td></tr>
                   <tr>

                           <td valign="top">
                                   Message Body:
                           </td>
                           <td>
                                   <textarea name="msg_body" rows=10 cols=50></textarea>
                           </td>
                   </tr>
                   <tr><td> </td></tr>
                   <tr>
                           <td colspan="2" align="center valign="middle">
                                   <input type="submit" value="Send" >
                           </td>
                   </tr>
           </table>
   </form>

                                                         Go To Index