Sendmail.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php namespace App\Controllers;
  2. use CodeIgniter\Controller;
  3. use PHPMailer\PHPMailer\PHPMailer;
  4. use PHPMailer\PHPMailer\OAuth;
  5. use PHPMailer\PHPMailer\Exception;
  6. use PHPMailer\PHPMailer\SMTP;
  7. use \App\Andy\CheckSpam;
  8. use \App\Andy\Utility;
  9. use CodeIgniter\I18n\Time;
  10. class Sendmail extends BaseController
  11. {
  12. protected $totalMessage;
  13. public function __construct()
  14. {
  15. parent::__construct();
  16. $this->myTime = parent::getTime();
  17. $this->myDate= date("d/m/Y",$this->myTime);
  18. }
  19. public function processform()
  20. {
  21. // $lucky= $this->request->getVar(csrf_token());
  22. //above checks csrf is working
  23. $cleanName= htmlentities( $this->request->getVar('name'));
  24. $cleanEmail= htmlentities($this->request->getVar('email'));
  25. $message= $this->request->getVar('message');
  26. $spamHandle = new CheckSpam();
  27. $utilityHandle= new Utility();
  28. //CheckSpam is in app/Andy and has namespace App\Andy
  29. $logic = $spamHandle->filterSpam($message);
  30. //before bothering to remove char check if spam
  31. if ($logic =="true")
  32. {
  33. $data = [
  34. 'title'=>'spam',
  35. 'date'=>$this->myDate
  36. ];
  37. echo view('spam',$data);
  38. }
  39. else
  40. {
  41. //start of else bracket
  42. $cleanMessage= $utilityHandle->removeScript($message);
  43. $cleanMessage= $utilityHandle->convertQuotes($cleanMessage);
  44. $cleanMessage = $utilityHandle->newRegex($cleanMessage);
  45. $IP= $_SERVER['REMOTE_ADDR'];
  46. $theirIP= strval($IP);
  47. $ip= $this->request->getIPAddress();
  48. $this->totalMessage = "new enquiry from a lovely web \r\n ".$cleanName ." \r\n their ip from native php is :".$theirIP."\r\n from CI4 get request its ".$ip."\r\n their email is: ".$cleanEmail." \r\n their message: ".$cleanMessage;
  49. $mail = new PHPMailer();
  50. $mail->isSMTP();
  51. $mail->Timeout = 20;
  52. $mail->SMTPDebug = 0;
  53. $mail->Host = 'smtp.gmail.com';
  54. $mail->Port = 587;
  55. $mail->SMTPSecure = 'tls';
  56. $mail->SMTPAuth = true;
  57. $mail->Username = "youremail@gmail.com";
  58. //Password to use for SMTP authentication
  59. $mail->Password = "password";
  60. //Set who the message is to be sent from
  61. $mail->setFrom('admin@webnameYouWant.com', 'admin');
  62. $mail->addAddress('AddressWhereYouWantMessageSent@gmail.com', ' ');
  63. $mail->Subject = 'new enquiry from your web name ';
  64. $mail->Body = $this->totalMessage;
  65. $logic2 = $result= $mail->send();
  66. if (($logic2==1) OR ($logic2=="true"))
  67. {
  68. $data = ['title' => 'darth',
  69. 'info' => 'your message was sent ',
  70. 'date'=>$this->myDate
  71. ];
  72. echo view ('info',$data);
  73. }
  74. }//end of else bracket
  75. }//end of process form method
  76. }