123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- <?php namespace App\Controllers;
- use CodeIgniter\Controller;
- use App\Andy\Utility;
- use PHPMailer\PHPMailer\PHPMailer;
- use PHPMailer\PHPMailer\OAuth;
- use PHPMailer\PHPMailer\Exception;
- use PHPMailer\PHPMailer\SMTP;
- use CodeIgniter\I18n\Time;
- class Attachment extends BaseController
- {
- protected $mimeType;
- protected $mimeLogic;
- protected $fileSize;
- protected $count;
- protected $newCount;
- protected $myTime;
- public function __construct()
- {
- parent::__construct();
- $this->myTime = parent::getTime();
- $this->myDate= date("d/m/Y",$this->myTime);
-
- }
-
- public function index()
- {
- echo "i am class Attachment, method index";
- }
- public function showForm()
- {
-
- $data =[
- 'title'=>'for attachment ',
- 'info'=>' ',
- 'count'=>'null',
- 'date'=>$this->myDate
- ];
-
- echo view('header',$data);
- echo view('attachForm',$data);
- echo view('footer',$data);
-
- }
- public function process()
- {
- session_start();
- helper('form');
- helper('html');
-
-
- $description = $this->request->getVar('fileDescription');
- $accessCode = $this->request->getVar('code');
- $file = $this->request->getFile('userfile');
- $fileName= $file->getName();
- $tempfile = $file->getTempName();
- $theFile = new \CodeIgniter\Files\File($tempfile);
- $this->mimeType= $theFile->getMimeType();
- $this->fileSize= $theFile->getSize('kb');
- $handle= new Utility();
- $this->mimeLogic= $handle->checkMime($this->mimeType);
-
- $ip = $_SERVER['REMOTE_ADDR'];
- $theIp = strval($ip);
-
-
- $theIp;
- $message =" enquiry for printing: \r\n"."their Ip address" .$theIp. " \r\n ". " file description ".$description. "";
-
-
-
-
-
-
-
- if ($accessCode!="000")
- {
-
- if(isset( $_SESSION['count']) ==false)
-
- {
-
- $_SESSION['count']= 5;
- $this->count= $_SESSION['count'];
- echo $this->count;
- }
-
- if(isset( $_SESSION['count']) ==true)
-
- {
- $this->count= $_SESSION['count'];
- $this->newCount=$this->count-1;
- $_SESSION['count']= $this->newCount;
-
-
-
- if ($_SESSION['count'] < 1)
-
- {
- return redirect('spam');
-
- }
-
- }
-
-
- $data =[
- 'title'=>'for attachment ',
- 'info'=>'you have no right to upload',
-
- ];
-
- echo view('header',$data);
- echo view('attachForm',$data);
- echo view('footer');
-
-
- exit();
-
-
- }
-
-
- if ($this->fileSize > 400 )
- {
-
-
- helper('form');
- helper('html');
-
- $data =[
- 'title'=>'for attachment ',
- 'info'=>'file too big max 400kb'
- ];
-
- echo view('header',$data);
- echo view('attachForm',$data);
- echo view('footer');
-
-
- exit();
-
-
- }
-
-
-
-
-
- if ($this->mimeLogic!=True)
- {
-
-
- helper('form');
- helper('html');
-
- $data =[
- 'title'=>'for attachment ',
- 'info'=>'thats not an allowed file '
- ];
-
- echo view('header',$data);
- echo view('attachForm',$data);
- echo view('footer');
-
-
- exit();
-
-
- }
-
-
-
-
-
-
-
- try
- {
-
-
-
-
-
- $mail = new PHPMailer();
- $mail->isSMTP();
- $mail->Timeout = 20;
- //Enable SMTP debugging, 0 = off (for production use), 1 = client messages, 2 = client and server messages
- $mail->SMTPDebug = 0;
- //Set the hostname of the mail server
- $mail->Host = 'smtp.gmail.com';
- $mail->Port = 587;
- $mail->SMTPSecure = 'tls';
- $mail->SMTPAuth = true;
- //Username to use for SMTP authentication - use full email address for gmail
- $mail->Username = "andybrookestar@gmail.com";
- //Password to use for SMTP authentication
- $mail->Password = "ewskcctyzsieqvhr";
- //Set who the message is to be sent from
- $mail->setFrom('andy@benxmidia.com', 'andy brookes');
- $mail->addAddress('andybrookestar@yahoo.com', 'andy');
- //$mail->addAddress('blackcatglm@gmail.com', 'benjain');
-
- $mail->addAttachment($tempfile,$fileName);
- //$mail->addReplyTo('replyto@example.com', 'First Last');
- //$mail->addAddress('ginaacheampong@gmail.com', 'gina');
- //$mail->AddCC('andybrookestar@yahoo.com','andy');
-
-
- //Set the subject line
- $mail->Subject = 'enquiry from benxmidia dev slackware ';
- //Read an HTML message body from an external file, convert referenced images to embedded,
- //convert HTML into a basic plain-text alternative body
- //$mail->msgHTML(file_get_contents('contents.html'), __DIR__);
- //Replace the plain text body with one created manually
- $mail->Body = $message;
- $logic2 = $result= $mail->send();
- }
-
- catch ( \Exception $e)
- {
- $data = [
- 'title' => 'info',
-
- 'info'=>'somwething went wrong '
- ];
- echo view('header', $data);
- echo view('info', $data);
- echo view('footer');
-
-
- die();
- //above try catch works
- }
-
-
-
-
- if($logic2== true)
-
- {
- $data =[
- 'title'=>'info ',
- 'info'=>'your file was sent'
- ];
-
- echo view('header',$data);
- echo view('info',$data);
- echo view('footer');
-
-
-
- }
-
-
-
-
- }//end process
- }//end class
|