This is my first OOP script, a PHP email script designed for a site I'm working on: ndkutz(.)net. I want a user to be able to send an email to the barbershop owner from the website. I'm self taught and even though I know I'm on the right track I feel absolutely lost. Is my code any good?
<?php
$error = '';
$errormsg = '';
$finalMessage = '';
$finalName = '';
$finalSubject = '';
$finalTo = '';
$finalHeader = '';
$sendingEmail = '';
class emailConstruction
{
private $from = "";
private $name = "";
private $message = "";
public function scrubAll($data) {
$data = htmlspecialchars($data);
$data = trim($data);
$data = strip_tags($data);
return $data;
}
public function setfrom($from){
$this->from = stripslashes($from);
$this->from = $from;
}
public function getFrom(){
return $this->from;
}
public function setName($name){
$this->name = scrubAll($name);
$this->name = $name;
}
public function getName(){
return $this->name;
}
public function setMessage($message){
$this->message = scrubAll($data);
$this->message = wordwrap($data,70,"<br />");
$this->message = $message;
}
public function getMessage(){
return $this->message;
}
}
if(isset($_POST['submit']))
{
if(empty($_POST['uname']))
{
$error = 1;
$errormsg = "Your name is required.";
return false;
}else{
$error = 0;
$createEmail = new emailConstruction;
$createEmail->setName($_POST['uname']);
}
if(empty($_POST['umail']))
{
$error = 1;
$errormsg = "Email address required.";
return false;
}else {
$error = 0;
$createEmail = new emailConstruction;
$createEmail->setTo($_POST['umail']);
}
if(empty($_POST['umsg']))
{
$error = 1;
$errormsg = "Message is required";
return false;
}else{
$error = 0;
$createEmail = new emailConstruction;
$createEmail->setMessage($_POST['umsg']);
}
if($error = 0)
{ $finalHeader = 'from:' . $finalFrom;
$finalHeader .='MIME-Version: 1.0\r\n';
$finalHeader .='Content-type: text/html\r\n';
$finalMessage = $createEmail->getMessage();
$finalName = $createEmail->getName();
$finalSubject = 'New potiential client by the name of ' . $finalName;
$finalTo = $createEmail->getTo();
$sendingEmail = mail($finalTo,$finalSubject,$finalMessage,$finalHeader);
if($sendingEmail == true)
{
$emailMessageS = 'Email sent successfully!';
}else{
$emailMessageF = 'Error. Please try again!';
}
}
}
?>
$email->sendTo('[email protected]');
to send it. \$\endgroup\$