gabrielkolbe Posted March 8, 2007 Share Posted March 8, 2007 hi, I am new to oo, created a simple email class which does not behave. When I run the class (below) so: if ($mail->sendMail($email, $_POST["subject"], $_POST["body"], $_POST["emailsender"])) { //to decode the above class it's (sendMail(to_emailaddress, subject, body, from_emailadress_or_name)) $message="Success!!"; } else { $error= "There was an error... "; } The email does go through BUT I get the error message the whole time, does anyone has any advice on this matter? <?PHP class email { var $to; var $from; var $subject; var $body; function validateEmail($testemail){ $regexp ="^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$"; if (eregi($regexp, $testemail)){return true;} else { return false;} } function sendMail( $to, $subject, $body, $from ) { $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "Content-Transfer-Encoding: 7bit\r\n"; $headers = "From: {$from} \r\n"; if ($this->validateEmail($to) == false) {$error = "email address {$to} is an invalid";} else { if ($this->validateEmail($from) == false) {$error = "email address {$from} is an invalid";} else { $body=stripslashes($body); $subject=stripslashes($subject); if (mail ($to, $subject, $body, $headers)) {$message = "Email {$subject} was send"; } else { $error = "There was an error in sending an email to {$to}"; } mail ('[email protected]', $subject, $body, $headers); } } print $message; print $error; } } ?> Link to comment https://forums.phpfreaks.com/topic/41786-email-class-behaving-strangly/ Share on other sites More sharing options...
skali Posted March 8, 2007 Share Posted March 8, 2007 <?PHP class email { var $to; var $from; var $subject; var $body; function validateEmail($testemail){ $regexp ="^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$"; if (eregi($regexp, $testemail)){return true;} else { return false;} } function sendMail( $to, $subject, $body, $from ) { $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "Content-Transfer-Encoding: 7bit\r\n"; $headers = "From: {$from} \r\n"; if ($this->validateEmail($to) == false) {$error = "email address {$to} is an invalid";} else { if ($this->validateEmail($from) == false) {$error = "email address {$from} is an invalid";} else { $body=stripslashes($body); $subject=stripslashes($subject); if (mail ($to, $subject, $body, $headers)){return true; } else {mail ('[email protected]', $subject, $body, $headers);return false;} } } } } $mail = new email(); $mail->sendMail($email, $_POST["subject"], $_POST["body"], $_POST["emailsender"]); ?> Link to comment https://forums.phpfreaks.com/topic/41786-email-class-behaving-strangly/#findComment-202671 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.