Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- view->mailsendview.php
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- ?><!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>Welcome to Mail Sender</title>
- <!-- meta tag -->
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <!-- font Awesome -->
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css">
- <!-- stylesheet -->
- <link rel="stylesheet" href="<?=base_url('assets/bootstrap-4.3.1-dist/css/bootstrap.min.css');?>">
- <link rel="stylesheet" href="<?=base_url('assets/css/custom/style.css');?>">
- </head>
- <body>
- <!-- Site Header -->
- <?php include('include/header.php') ?>
- <!-- Main Contain Start -->
- <div class="container">
- <div class="row top-buffer justify-content-center">
- <div class="col-md-8">
- <form class="top-buffer" id="mail_form" action="" method="POST" enctype="multipart/form-data">
- <div class="form-row">
- <div class="form-group col-md-5">
- <label for="user_mail">UserMail :</label>
- <input type="text" class="form-control" name="user_mail" id="user_mail" placeholder="User Mail" value="" autocomplete="off" required>
- </div>
- <div class="form-group col-md-5">
- <label for="user_pass">UserPass :</label>
- <input type="password" class="form-control" name="user_pass" id="user_pass" placeholder="User Password" value="" autocomplete="off" required>
- </div>
- </div>
- <div class="form-row">
- <div class="form-group col-md-5">
- <label for="from_mail">From Mail</label>
- <input type="email" class="form-control" name="from_mail" id="from_mail" placeholder="From Mail" autocomplete="off" data-error="Email address is invalid" required>
- </div>
- <div class="form-group col-md-5">
- <label for="from_name">From Name</label>
- <input type="text" class="form-control" name="from_name" id="from_name" placeholder="From Name" autocomplete="off" required>
- </div>
- </div>
- <div class="form-row">
- <div class="form-group col-md-10">
- <label for="to_mail">To Mail</label>
- <input type="email" class="form-control" name="to_mail" id="to_mail" placeholder="To Mail" autocomplete="off" required>
- </div>
- </div>
- <div class="form-row">
- <div class="form-group col-md-10">
- <label for="mail_subject">Mail Subject</label>
- <input type="text" class="form-control" name="mail_subject" id="mail_subject" placeholder="Mail Subject" autocomplete="off" data-error="Email address is invalid" required>
- </div>
- </div>
- <div class="form-row">
- <div class="form-group col-md-10">
- <label for="mail_text">Mail Text</label>
- <textarea class="form-control" name="mail_text" id="mail_text" style="resize: none;" rows="10" required></textarea>
- </div>
- </div>
- <div class="form-row">
- <div class="form-group col-md-5">
- <label>No Of Mail :</label>
- <input type="number" name="mail_counter" min="1" max="20" required>
- </div>
- <div class="form-group col-md-5">
- <button type="button" name="send_mail_btn" id="send_mail_btn" class="btn btn-primary">Sent Mail</button>
- </div>
- </div>
- </form>
- </div>
- </div>
- </div>
- <!-- Main Contain End -->
- <!-- Site Footer -->
- <?php include('include/footer.php') ?>
- <!-- JavaScript Here -->
- <script src="<?=base_url('assets/js/jquery-3.4.1/jquery-3.4.1.js');?>"></script>
- <script src="<?=base_url('assets/js/form-validate/jquery.validate.min.js');?>"></script>
- <script src="<?=base_url('assets/bootstrap-4.3.1-dist/js/bootstrap.min.js');?>"></script>
- <!-- Toastr Notification -->
- <?php include 'alert.php'; ?>
- <script type="text/javascript">
- $(document).on('click', '#send_mail_btn', function(){
- var valid = $('#mail_form').valid();
- if(valid == true)
- {
- $("#send_mail_btn").attr("disabled", "disabled");
- alert("Mail Sending.....");
- var formData = new FormData($('#mail_form')[0]);
- $.ajax({
- url:'<?= base_url(); ?>/welcome/mailsent',
- method:"POST",
- data:formData,
- success:function(data){
- $("#send_mail_btn").removeAttr("disabled");
- alert("Mail Sent....");
- //document.getElementById("mail_form").reset();
- },
- cache: false,
- contentType: false,
- processData: false,
- })
- }
- });
- </script>
- </body>
- </html>
- controller->file
- public function mailview()
- {
- $this->load->view('MailSentView');
- }
- public function mailsent()
- {
- $from_mail = $_REQUEST["user_mail"];
- $user_pass = $_REQUEST["user_pass"];
- $from_mail = $_REQUEST["from_mail"];
- $from_name = $_REQUEST["from_name"];
- $to_mail = $_REQUEST["to_mail"];
- $mail_subject = $_REQUEST["mail_subject"];
- $mail_text = $_REQUEST["mail_text"];
- $mail_counter = $_REQUEST["mail_counter"];
- for ($x = 1; $x <= $mail_counter; $x++) {
- //echo "The number is: $x <br>";
- $config = Array(
- 'protocol' => 'smtp',
- 'smtp_host' => 'ssl://smtp.googlemail.com',
- 'smtp_port' => 465,
- 'smtp_user' => $from_mail,
- 'smtp_pass' => $user_pass,
- 'mailtype' => 'html',
- 'charset' => 'iso-8859-1'
- );
- $this->load->library('email', $config);
- $this->email->set_newline("\r\n");
- $this->email->initialize($config);
- $this->email->from($from_mail, $from_name);
- $this->email->to($to_mail);
- // $this->email->cc('');
- // $this->email->bcc('');
- $this->email->subject($mail_subject." ".$x);
- $this->email->message($mail_text);
- // $this->email->send()
- if($this->email->send()){
- //Success email Sent
- //echo $this->email->print_debugger();
- }else{
- //Email Failed To Send
- //echo $this->email->print_debugger();
- }
- // $result = $this->email->send();
- }
- }
Add Comment
Please, Sign In to add comment