In this example we using Views and Controller Structure for send email.
Here is the Controller file hello.php which inside controllers folder
controllers/hello.php
<?php
class Hello extends Controller {
function __construct() {
parent::__construct();
}
function send_mail(){
if(isset($_POST['send']))
{
$to_email=$_POST['to'];
$subject=$_POST['subject'];
$message=$_POST['message'];
$to = $to_email;
$subject = $subject;
$txt = $message;
$headers = "From: admin@gmail.com" . "\r\n" .
"CC: anymail@example.com";
mail($to,$subject,$txt,$headers);
}
$this->view->render('hello/send_mail');
}
}
?>
Here is the view file send_mail.php which inside views folder contains the form.
views/hello/send_mail.php
<!DOCTYPE html>
<html>
<body>
<form method="post" action="send_mail">
To:<br>
<input type="email" name="to"><br>
Subject:<br>
<input type="text" name="subject"><br><br>
Message:
<textarea rows="4" cols="40" name="message"> </textarea>
<input type="submit" name="send">
</form>
</html>
</body>