note 52071 added to function.mail

From: Date: Wed, 20 Apr 2005 14:18:22 +0000
Subject: note 52071 added to function.mail
Groups: php.notes 
Request: Send a blank email to php-notes+get-88271@lists.php.net to get a copy of this message
<?php class clsMail { var $to; var $from; var $cc; var $bcc; var $subject; var $message; var $contentType; function clsMail() //init { $this->to = ""; $this->from = ""; $this->cc = ""; $this->bcc = ""; $this->subject = ""; $this->message = ""; $this->contentType = "html"; // text, html } function isemail($email) { // regx to test for valid e-mail adres $regex = '^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]{2,})+$'; if (eregi($regex, $email)) return true; else return false; } function send() { // check if e-mail adresses are valid. if (!clsMail::isemail($this->to)) die('ERROR: Invalid To e-mail adres'); if (!clsMail::isemail($this->from)) die('ERROR: Invalid From e-mail adres'); if (!clsMail::isemail($this->cc) && !$this->cc=="") die('ERROR: Invalid CC e-mail adres'); if (!clsMail::isemail($this->bcc) && !$this->bcc=="") die('ERROR: Invalid BCC e-mail adres'); // To send HTML mail, you can set the Content-type header. html is the default $headers = "MIME-Version: 1.0\r\n"; if ($this->contentType=="html") $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; else $headers .= "Content-type: text/plain; charset=us-ascii\r\n"; // additional headers for From, Cc and Bcc $headers .= "From: ".$this->from."\r\n"; if (!$this->cc=="") $headers .= "Cc: ".$this->cc."\r\n"; if (!$this->bcc=="") $headers .= "Bcc: ".$this->bcc."\r\n"; // send the e-mail return mail($this->to, $this->subject, $this->message, $headers); } } // example how te use the mail class $mail = new clsMail(); $mail->to="someone@domain.com"; $mail->from="me@domain.com"; $mail->subject="My Subject"; $mail->message="My Message body"; echo $mail->send(); // returns true or false at failure ?> ---- Manual Page -- http://www.php.net/manual/en/function.mail.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52071 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52071&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52071&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52071&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52071&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52071&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52071&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#88271) next »