Booking and contact messqge

This commit is contained in:
CHIEFSOFT\ameye
2024-09-29 17:47:32 -04:00
parent c6a097d333
commit e5fad97e49
5 changed files with 201 additions and 12 deletions
+5 -5
View File
@@ -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
+2
View File
@@ -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');
+189 -3
View File
@@ -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;
}
}
+3 -3
View File
@@ -121,19 +121,19 @@
<div class="form-group col-md-6 mb-4">
<label>How many vehicles does your business have ?(Required)</label>
<input type="email" name ="email" class="form-control" id="email" placeholder="Enter Number" required>
<input type="text" name ="numcars" class="form-control" id="numcars" placeholder="Enter Number" required>
<div class="help-block with-errors"></div>
</div>
<div class="form-group col-md-6 mb-4">
<label>How many vehicles do you need ? (Required)</label>
<input type="text" name="phone" class="form-control" id="phone" placeholder="Enter Number" required>
<input type="text" name="numneed" class="form-control" id="numneed" placeholder="Enter Number" required>
<div class="help-block with-errors"></div>
</div>
<div class="form-group col-md-12 mb-4">
<label>Company Name (Required)</label>
<input type="text" name="phone" class="form-control" id="phone" placeholder="Enter Number" required>
<input type="text" name="company" class="form-control" id="company" placeholder="Company Name" required>
<div class="help-block with-errors"></div>
</div>
+2 -1
View File
@@ -94,7 +94,7 @@
<!-- Section Title End -->
<!-- Contact Form Start -->
<div class="contact-us-form">
<form id="contactForm" action="#" method="POST" data-toggle="validator" class="wow fadeInUp" data-wow-delay="0.5s">
<form id="MycontactForm" action="/contact" method="POST" data-toggle="validator" class="wow fadeInUp" data-wow-delay="0.5s">
<div class="row">
<div class="form-group col-md-6 mb-4">
<label>first name</label>
@@ -130,6 +130,7 @@
<div class="contact-form-btn">
<button type="submit" class="btn-default">send message</button>
<div id="msgSubmit" class="h3 hidden"></div>
<div> <?= $contact_sent ?? '' ?></div>
</div>
</div>
</div>