diff --git a/app/Config/Email.php b/app/Config/Email.php index 4dce650..8883afe 100644 --- a/app/Config/Email.php +++ b/app/Config/Email.php @@ -28,22 +28,22 @@ class Email extends BaseConfig /** * SMTP Server Hostname */ - public string $SMTPHost = ''; + public string $SMTPHost = 'smtp.googlemail.com'; /** * SMTP Username */ - public string $SMTPUser = ''; + public string $SMTPUser = 'support@chiefsoft.com'; /** * SMTP Password */ - public string $SMTPPass = ''; + public string $SMTPPass = 'may12002!'; /** * SMTP Port */ - public int $SMTPPort = 25; + public int $SMTPPort = 465; //25; /** * SMTP Timeout (in seconds) @@ -62,7 +62,7 @@ class Email extends BaseConfig * to the server. 'ssl' means implicit SSL. Connection on port * 465 should set this to ''. */ - public string $SMTPCrypto = 'tls'; + public string $SMTPCrypto = 'ssl'; // 'tls'; /** * Enable word-wrap diff --git a/app/Config/Routes.php b/app/Config/Routes.php index bca3cde..28d19f3 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -8,5 +8,7 @@ use CodeIgniter\Router\RouteCollection; $routes->get('/', 'Home::index'); $routes->get('/about', 'Home::about'); $routes->get('/contact', 'Home::contact'); +$routes->post('/contact', 'Home::contact'); $routes->get('/book', 'Home::book'); +$routes->post('/book', 'Home::book'); $routes->get('/our-service', 'Home::ourService'); diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php index 46d984a..e9068b8 100644 --- a/app/Controllers/Home.php +++ b/app/Controllers/Home.php @@ -2,7 +2,7 @@ namespace App\Controllers; -class Home extends BaseController +class Home extends basecontroller { public function index(): string { @@ -43,17 +43,203 @@ class Home extends BaseController } public function contact(): string { - return view('contact'); + + + +// $email = service('email'); +// +// +// $config['SMTPHost'] = 'smtp.googlemail.com'; +// $config['SMTPUser'] = 'support@chiefsoft.com'; +// $config['SMTPPass'] = 'may12002!'; +// $config['SMTPPort'] = '465'; +// +// $config['SMTPCrypto'] = 'ssl'; +// +// $config['protocol'] = 'sendmail'; +// $config['mailPath'] = '/usr/sbin/sendmail'; +// $config['charset'] = 'iso-8859-1'; +// $config['wordWrap'] = true; +// +// $email->initialize($config); +// +// $email->setFrom('support@gmail.com', 'ChiefsoftWorks Support'); +// $email->setTo('ses66181@gmail.com'); +////$email->setCC('another@another-example.com'); +////$email->setBCC('them@their-example.com'); +// +// $email->setSubject('Email Test'); +// $email->setMessage('Testing the email class.'); +// +// $email->send(); + + $data = []; + if ($_POST){ + $message = $this->contactMessage(); + // echo "ameye 00 ......"; + $data['contact_sent'] = $this->pushEmail($message); + } + + + + + + return view('contact',$data); + } + private function bookMessage():string{ + $errorMSG = ""; + $fname = $lname = $email = $phone = $message = ''; + // FIRSTNAME + if (empty($_POST["fname"])) { + $errorMSG = "Full Name is required. "; + } else { + $fname = $_POST["fname"]; + } + + // LASTNAME + if (empty($_POST["lname"])) { + $errorMSG = "Full Name is required. "; + } else { + $lname = $_POST["lname"]; + } + + // EMAIL + if (empty($_POST["email"])) { + $errorMSG .= "Email is required. "; + } else { + $email = $_POST["email"]; + } + + // PHONE + if (empty($_POST["phone"])) { + $errorMSG .= "Phone is required. "; + } else { + $phone = $_POST["phone"]; + } + + // MESSAGE + if (empty($_POST["message"])) { + $errorMSG .= "Message is required. "; + } else { + $message = $_POST["message"]; + } + + + + // prepare email body text + $Body = ""; + $Body .= "Name: "; + $Body .= $fname." ".$lname; + $Body .= "\n"; + $Body .= "Email: "; + $Body .= $email; + $Body .= "\n"; + $Body .= "Phone: "; + $Body .= $phone; + $Body .= "\n"; + $Body .= "Message: "; + $Body .= $message; + $Body .= "\n"; + + + return $Body; + } + + private function contactMessage():string{ + $errorMSG = ""; + $fname = $lname = $email = $phone = $message = ''; + // FIRSTNAME + if (empty($_POST["fname"])) { + $errorMSG = "Full Name is required. "; + } else { + $fname = $_POST["fname"]; + } + + // LASTNAME + if (empty($_POST["lname"])) { + $errorMSG = "Full Name is required. "; + } else { + $lname = $_POST["lname"]; + } + + // EMAIL + if (empty($_POST["email"])) { + $errorMSG .= "Email is required. "; + } else { + $email = $_POST["email"]; + } + + // PHONE + if (empty($_POST["phone"])) { + $errorMSG .= "Phone is required. "; + } else { + $phone = $_POST["phone"]; + } + + // MESSAGE + if (empty($_POST["message"])) { + $errorMSG .= "Message is required. "; + } else { + $message = $_POST["message"]; + } + + + + // prepare email body text + $Body = ""; + $Body .= "Name: "; + $Body .= $fname." ".$lname; + $Body .= "\n"; + $Body .= "Email: "; + $Body .= $email; + $Body .= "\n"; + $Body .= "Phone: "; + $Body .= $phone; + $Body .= "\n"; + $Body .= "Message: "; + $Body .= $message; + $Body .= "\n"; + + + return $Body; } public function book(): string { - return view('book'); + $data = []; + if ($_POST){ + $message = $this->bookMessage(); + $data['contact_sent'] = $this->pushEmail($message); + } + return view('book',$data); } public function ourService(): string { return view('our-services'); } + private function pushEmail($message) : string + { + $to = 'johnbullenterprises@gmail.com'; //'ses66181@gmail.com';//Type here the mail address where you want to send + $subject = 'Subject of Email';//Write here Subject of Email + //$message="Congrats ! You did it.";//Write the message you want to send + //$email = \Config\Services::email(); + + $email = service('email'); + $email->setTo($to); + $email->setFrom('support@chiefsoft.com', 'Contact Message');//set From + $email->setSubject($subject); + $email->setMessage($message); + if($email->send()) + { + $contact_sent = "Email has been Sent."; + } + else{ + $contact_sent= "Something went wrong !"; + $contact_sent =''; + } + /* */ + return $contact_sent; +} } diff --git a/app/Views/book.php b/app/Views/book.php index deca28f..1d4f691 100644 --- a/app/Views/book.php +++ b/app/Views/book.php @@ -121,19 +121,19 @@
- +
- +
- +
diff --git a/app/Views/contact.php b/app/Views/contact.php index 191ef39..5e25357 100644 --- a/app/Views/contact.php +++ b/app/Views/contact.php @@ -94,7 +94,7 @@
-
+
@@ -130,6 +130,7 @@
+