kirim email using codeigniter 4
<?php namespace App\Controllers;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
class Kirim_email extends BaseController
{
public function __construct()
{
helper(['form']);
}
public function index()
{
return view('v_form_kirim_email');
}
public function send()
{
$to = $this->request->getPost('to');
$subject = $this->request->getPost('subject');
$message = $this->request->getPost('message');
$mail = new PHPMailer(true);
try {
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->Host = 'smtp.googlemail.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]'; // silahkan ganti dengan alamat email Anda
$mail->Password = 'password_email'; // silahkan ganti dengan password email Anda
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->setFrom('[email protected]', 'Ilmu Coding'); // silahkan ganti dengan alamat email Anda
$mail->addAddress($to);
$mail->addReplyTo('[email protected]', 'Ilmu Coding'); // silahkan ganti dengan alamat email Anda
// Content
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->send();
session()->setFlashdata('success', 'Send Email successfully');
return redirect()->to('/kirim_email');
} catch (Exception $e) {
session()->setFlashdata('error', "Send Email failed. Error: ".$mail->ErrorInfo);
return redirect()->to('/kirim_email');
}
}
}
Are there any code examples left?
New code examples in category PHP
-
PHP 2022-03-27 22:40:03 index:of curiosa 2019 mp4
-
PHP 2022-03-27 22:35:13 Dijkstra’s algorithm php
-
PHP 2022-03-27 22:35:12 get_declared_classes
-
PHP 2022-03-27 22:30:23 php move index of a value to first position in array
-
PHP 2022-03-27 22:25:01 wordpress get_date
-
PHP 2022-03-27 21:30:38 php shorten string with dots
-
PHP 2022-03-27 21:10:46 php header 500
-
PHP 2022-03-27 21:05:06 laravel schedule run
-
PHP 2022-03-27 20:25:12 Get page title, excerpt or content by id
-
PHP 2022-03-27 20:00:27 php convert date from dd/mm/yyyy to yyyy-mm-dd