EVOLUTION-NINJA
Edit File: 1732607300email.txt
public function sendEmail() { $email = \Config\Services::email(); $db = \config\Database::connect(); $builder = $db->table('users'); $name = $this->request->getpost('name'); $lastname = $this->request->getpost('lastname'); $to = $this->request->getpost('to'); $service = $this->request->getpost('service'); $comment = $this->request->getpost('comment'); $data = [ 'name'=>$name, 'lastname'=>$lastname, 'to'=>$to, 'service'=>$service, 'comment'=>$comment, ]; $res = $builder->insert($data); $to = $this->request->getPost('to'); $subject = $this->request->getPost('subject'); $message = $this->request->getPost('message'); $email->setFrom('enquiry09.gta@gmail.com', 'G-Track'); $email->setTo($to); $email->setSubject("this message from gtrack"); $email->setMessage('thank you for your enquery'); if ($email->send() && $res) { // return view('contactus'); return $this->response->setJSON(['status'=>'success']); } else { echo $email->printDebugger(['headers']); } } ajax $(document).ready(function(){ $('#form').on('submit', function(e){ e.preventDefault(); var formData = $(this).serialize(); $.ajax({ url: '<?php echo site_url('send/email') ?>', method: 'POST', data: formData, success: function(response){ if(response.status === 'success'){ alert('Thank you for Contract Us'); $('#form')[0].reset(); } else { alert('Failed to send email'); } }, error: function(){ alert('An error occurred during the AJAX request'); } }); }); }); pohp email <?php namespace Config; use CodeIgniter\Config\BaseConfig; class Email extends BaseConfig { public string $fromEmail = 'enquiry09.gta@gmail.com'; public string $fromName = 'G-Track'; public string $recipients = ''; public string $userAgent = 'CodeIgniter'; public string $protocol = 'smtp'; // Gmail SMTP configuration public string $SMTPHost = 'smtp.gmail.com'; public string $SMTPUser = 'enquiry09.gta@gmail.com'; public string $SMTPPass = 'phiw kvrj kofj jfid'; // Use your App Password here public int $SMTPPort = 587; public int $SMTPTimeout = 5; public bool $SMTPKeepAlive = false; public string $SMTPCrypto = 'tls'; // Other email configuration options public bool $wordWrap = true; public int $wrapChars = 76; public string $mailType = 'text'; public string $charset = 'UTF-8'; public bool $validate = false; public int $priority = 3; public string $CRLF = "\r\n"; public string $newline = "\r\n"; public bool $BCCBatchMode = false; public int $BCCBatchSize = 200; public bool $DSN=false; }