Zend - The PHP Company




Email

Add Code


simple email application  

Type: code fragment
Added by: sultanzahir
Entered: 13/08/2001
Last modified: 01/11/2000
Rating: - (fewer than 3 votes)
Views: 11715
This is a simple webapplication using sendmail and PHP Just cut and paste script and no database required.


<?

if ($senderEmail  !='' )
{

     
// echo '<body bgcolor="#ccdfed">' ;
     //  for ($i=0 ; $i < 500 ;$i++)
    // {


    //  mail("$toList", "$subject",$message, "FROM:$senderEmail");
    //  Echo "your message was successfully send" ;
//  }







                    
class email {

                            
// the constructor!
                            
function email $subject$message$senderName$senderEmail$toList$ccList=0$bccList=0$replyTo=0) {
                                    
$this->sender $senderName " <$senderEmail>";
                                    
$this->replyTo $replyTo;
                                    
$this->subject $subject;
                                    
$this->message $message;

                                    
// set the To: recipient(s)
                                    
if ( is_array($toList) ) {
                                            
$this->to join$toList"," );
                                    } else {
                                            
$this->to $toList;
                                    }

                                    
// set the Cc: recipient(s)
                                    
if ( is_array($ccList) && sizeof($ccList) ) {
                                            
$this->cc join$ccList"," );
                                    } elseif ( 
$ccList ) {
                                            
$this->cc $ccList;
                                    }

                                    
// set the Bcc: recipient(s)
                                    
if ( is_array($bccList) && sizeof($bccList) ) {
                                            
$this->bcc join$bccList"," );
                                    } elseif ( 
$bccList ) {
                                            
$this->bcc $bccList;
                                    }

                            }


                            function 
send () {
                                    
// create the headers needed by PHP's mail() function

                                    // sender
                                    
$this->headers "From: " $this->sender "n";

                                    
// reply-to address
                                    
if ( $this->replyTo ) {
                                            
$this->headers .= "Reply-To: " $this->replyTo "n";
                                    }

                                    
// Cc: recipient(s)
                                    
if ( $this->cc ) {
                                            
$this->headers .= "Cc: " $this->cc "n";
                                    }

                                    
// Bcc: recipient(s)
                                    
if ( $this->bcc ) {
                                            
$this->headers .= "Bcc: " $this->bcc "n";
                                    }

                                    return 
mail $this->to$this->subject$this->message$this->headers );
                            }
                    }
                    
$m = new email "$subject",
                                 
"$message",           // message body
                                   
"$senderName",                   // sender's name
                                 
"$senderEmail",         // sender's email
                                      
array("$toList"), // To: recipients
                                       
"$ccList",
                                       
"$bccList",
                                       
"$replyTo"     // Cc: recipient
                                   
);

                         print 
"mail sent, " $m->send();


                }

    else
    {

?>



<html>
<head></head>


<body bgcolor="#ccdfed">
<center><font size="+2" color="slategray"> Welcome to Email Utility</font></center>

<form method=post action="email.php" ENCTYPE="multipart/form-data">

<table width="500" align="center">
<tr>
<td>Your Name :</td><td><input type="text" name="senderName" size="40"></td></tr><tr>
<td>Your email  :</td><td><input type="text" name="senderEmail" size="40"></td></tr><tr>
<td>Reply to  :</td><td><input type="text" name="replyTo" size="40"></td></tr><tr>
<td>To :</td><td><input type="text" name="toList" value="<? echo $reciever ?>" size="40"></td></tr><tr>
<td>Cc :</td><td><input type="text" name="ccList"  size="40"></td></tr><tr>
<td>Bcc :</td><td><input type="text" name="bccList" size="40"></td></tr><tr>

<td>Subject :</td><td><input type="text" name="subject"  size="40"  value="<? echo $subject ?>"></td></tr><tr>
<td>Message :</td><td><textarea name="message" cols=39 rows="12"></textarea></td></tr>
<td>Attachment :</td><td><input TYPE="file" NAME="myfile" SIZE=30></td></tr>

</tr><tr>
<td></td><td><input type="submit" value="send"><input type="reset" value="Reset"></td></tr>
</table>
</form>
<?
}
?>


Usage Example


See the example


Rate This Script





Search



This Category All Categories