Sendmail.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. //$myTime = new Time('now');
  22. //$date= $myTime->toLocalizedString('MMM d, yyyy');
  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 queck 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 AndrinDesign \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. //Enable SMTP debugging, 0 = off (for production use), 1 = client messages, 2 = client and server messages
  53. $mail->SMTPDebug = 0;
  54. //Set the hostname of the mail server
  55. $mail->Host = 'smtp.gmail.com';
  56. $mail->Port = 587;
  57. $mail->SMTPSecure = 'tls';
  58. $mail->SMTPAuth = true;
  59. //Username to use for SMTP authentication - use full email address for gmail
  60. $mail->Username = "*******@gmail.com";
  61. //Password to use for SMTP authentication
  62. $mail->Password = "***********";
  63. //Set who the message is to be sent from
  64. $mail->setFrom('admin@yourdomain', 'john Doe');
  65. $mail->addAddress('emailAddressWhereMeesageShouldBeSent', 'John Doe');
  66. //Set the subject line
  67. $mail->Subject = 'new enquiry from web app starter girlsbeyourself ';
  68. $mail->Body = $this->totalMessage;
  69. $logic2 = $result= $mail->send();
  70. if (($logic2==1) OR ($logic2=="true"))
  71. {
  72. $data = ['title' => 'darth',
  73. 'info' => 'your message was sent ',
  74. 'date'=>$this->myDate
  75. ];
  76. echo view ('info',$data);
  77. }
  78. }//end of else bracket
  79. }
  80. }