note 69561 added to function.mail

From: Date: Mon, 11 Sep 2006 00:44:09 +0000
Subject: note 69561 added to function.mail
Groups: php.notes 
Request: Send a blank email to php-notes+get-116994@lists.php.net to get a copy of this message
Simple PHP5 mail class your convenience: <? class PhpMail { private static mregex = '/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]{2,})+$/i'; public static function isValidEmailString($email){ return preg_match(mregex,$email); } private $sTo,$sFrom,$sCc,$sBcc,$sSubject,$sMessage,$sContentType; public function __construct($contentType="plain"){ $sTo=null;$sFrom=null;$sCc=null;$sBcc=null; $sSubject=null;$sMessage=null; if($contentType=="plain"||$contentType=="html") $this->sContentType = $contentType; else throw new Exception("PHPMail Error: \\"Bad Content-Type\\""); } public function setFromAddress($email,$name=null){ $this->sFrom = $this->getFormattedAddress($email,$name); } public function addToAddress($email,$name=null){ $this->sTo .= $this->getFormattedAddress($email,$name).", "; } public function addCcAddress($email,$name=null){ $this->sCc .= $this->getFormattedAddress($email,$name).", "; } public function addBccAddress($email,$name=null){ $this->sBcc .= $this->getFormattedAddress($email,$name).", "; } public function setSubject($subject){$this->sSubject=$subject;} public function getSubject(){return $this->sSubject;} public function setMessage($message){$this->sMessage=$message;} public function getMessage(){return $this->sMessage;} public function send(){ if($this->sTo!=null||$this->sFrom!=null){ $headers = "MIME-Version: 1.0\\r\\n"; $headers .= "Content-type: text/".$this->sContentType.";charset=iso-8859-1\\r\\n"; $headers .= "From: ".$this->sFrom."\\r\\n"; $headers .= $this->sCc==null?"":"Cc: ".$this->sCc."\\r\\n"; $headers .= $this->sBcc==null?"":"Bcc: ".$this->sBcc."\\r\\n"; $headers .= "Return-Path: ".$this->sFrom; return @mail($this->sTo,$this->sSubject,$this->sMessage,$headers); } else return false; } private function getFormattedAddress($email,$name){ if(self::isValidEmailString($email)) return ($name==null? "" : "\\"$name\\" ") ."<$email>"; else throw new Exception("PhpMail Error: \\"Bad Email String\\""); } } ?> ---- Server IP: 216.194.113.175 Probable Submitter: 69.222.71.20 ---- Manual Page -- http://www.php.net/manual/en/function.mail.php Edit -- https://master.php.net/note/edit/69561 Del: integrated -- https://master.php.net/note/delete/69561/integrated Del: useless -- https://master.php.net/note/delete/69561/useless Del: bad code -- https://master.php.net/note/delete/69561/bad+code Del: spam -- https://master.php.net/note/delete/69561/spam Del: non-english -- https://master.php.net/note/delete/69561/non-english Del: in docs -- https://master.php.net/note/delete/69561/in+docs Del: other reasons-- https://master.php.net/note/delete/69561 Reject -- https://master.php.net/note/reject/69561 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#116994) next »