Advertisement
Guest User

Untitled

a guest
Nov 13th, 2017
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. require_once("lib/Smarty-3.1.3/Smarty.class.php");
  5. $smarty = new Smarty();
  6. $smarty->assign('title', 'Tytuł :D');
  7. $smarty -> display('indexAPMmail.tpl');
  8.  
  9. use PHPMailer\PHPMailer\PHPMailer;
  10. require __DIR__ . '/vendor/autoload.php'; //Load composer's autoloader
  11.  
  12. class APMmail {
  13. private $CharSet;
  14. private $isSMTP;
  15. private $Host;
  16. private $SMTPAuth;
  17. private $Username;
  18. private $Password;
  19. private $SMTPSecure;
  20. private $Port;
  21. private $mail;
  22. private $email_sender;
  23. private $email_recipient;
  24. private $subject;
  25. private $message;
  26.  
  27. public function __construct($config) {
  28. $this->mail = new PHPMailer(true);
  29. $this->mail->isSMTP();
  30. $this->mail->CharSet = $config['CharSet'];
  31. $this->mail->Host = $config['Host'];
  32. $this->mail->SMTPAuth = $config['SMTPAuth'];
  33. $this->mail->Username = $config['Username'];
  34. $this->mail->Password = $config['Password'];
  35. $this->mail->SMTPSecure = $config['SMTPSecure'];
  36. $this->mail->Port = $config['Port'];
  37. }
  38.  
  39. public function set_sender($emailSender){
  40. $this->email_sender = $emailSender;
  41. }
  42.  
  43. public function get_sender()
  44. {
  45. return $this->email_sender;
  46. }
  47.  
  48. public function set_Recipient($emailRecipient){
  49. $this->email_recipient = $emailRecipient;
  50. }
  51.  
  52. public function set_Subject($subject){
  53. $this->subject = $subject;
  54. }
  55.  
  56. public function set_Message($message){
  57. $this->message = $message;
  58. }
  59.  
  60. public function send_mail(){
  61. $this->mail->setFrom($this->email_sender, $this->email_sender);
  62. $this->mail->addAddress($this->email_recipient, $this->email_recipient); // Add a recipient
  63. //$mail->addAddress('ellen@example.com'); // Name is optional
  64. $this->mail->addReplyTo($this->email_sender, $this->email_sender);
  65. //$mail->addCC('cc@example.com');
  66. //$mail->addBCC('bcc@example.com');
  67.  
  68. //Attachments
  69. //$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
  70. //$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
  71.  
  72. //Content
  73. $this->mail->isHTML(true); // Set email format to HTML
  74. $this->mail->Subject = $this->subject;
  75. $this->mail->Body = $this->message;
  76.  
  77. $html = new \Html2Text\Html2Text($this->mail->Body);
  78. $this->mail->AltBody = $html->getText();
  79.  
  80. if(!$this->mail->send()){
  81. return false;
  82. echo 'Mailer Error: ' . $this->mail->ErrorInfo;
  83. } else {
  84. return true;
  85. }
  86. }
  87. }
  88.  
  89. if(isset($_POST['emailSender'])){
  90. $config = (object)[
  91. 'emailRecipient' => $_POST['emailRecipient'],
  92. 'subject' => $_POST['subject'],
  93. 'message' => $_POST['message'],
  94. ];}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement