Advertisement
Guest User

Untitled

a guest
Nov 13th, 2017
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 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. class APMmail {
  12. private $CharSet;
  13. private $isSMTP;
  14. private $Host;
  15. private $SMTPAuth;
  16. private $Username;
  17. private $Password;
  18. private $SMTPSecure;
  19. private $Port;
  20. private $mail;
  21. private $email_sender;
  22. private $email_recipient;
  23. private $subject;
  24. private $message;
  25.  
  26. public function __construct($serverConfig) {
  27. $this->mail = new PHPMailer(true);
  28. $this->mail->isSMTP();
  29. $this->mail->CharSet = $serverConfig['CharSet'];
  30. $this->mail->Host = $serverConfig['Host'];
  31. $this->mail->SMTPAuth = $serverConfig['SMTPAuth'];
  32. $this->mail->Username = $serverConfig['Username'];
  33. $this->mail->Password = $serverConfig['Password'];
  34. $this->mail->SMTPSecure = $serverConfig['SMTPSecure'];
  35. $this->mail->Port = $serverConfig['Port'];
  36. }
  37.  
  38. public function set_sender($emailSender){
  39. $this->email_sender = $emailSender;
  40. }
  41.  
  42. public function get_sender()
  43. {
  44. return $this->email_sender;
  45. }
  46.  
  47. public function set_Recipient($emailRecipient){
  48. $this->email_recipient = $emailRecipient;
  49. }
  50.  
  51. public function set_Subject($subject){
  52. $this->subject = $subject;
  53. }
  54.  
  55. public function set_Message($message){
  56. $this->message = $message;
  57. }
  58.  
  59. public function send_mail($config, $serverConfig){
  60. $this->mail->setFrom($this->email_sender, $this->email_sender);
  61. $this->mail->addAddress($this->email_recipient, $this->email_recipient); // Add a recipient
  62. //$mail->addAddress('ellen@example.com'); // Name is optional
  63. $this->mail->addReplyTo($this->email_sender, $this->email_sender);
  64. //$mail->addCC('cc@example.com');
  65. //$mail->addBCC('bcc@example.com');
  66.  
  67. //Attachments
  68. //$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
  69. //$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
  70.  
  71. //Content
  72. $this->mail->isHTML(true); // Set email format to HTML
  73. $this->mail->Subject = $this->subject;
  74. $this->mail->Body = $this->message;
  75.  
  76. $html = new \Html2Text\Html2Text($this->mail->Body);
  77. $this->mail->AltBody = $html->getText();
  78.  
  79. if(!$this->mail->send()){
  80. return false;
  81. echo 'Mailer Error: ' . $this->mail->ErrorInfo;
  82. } else {
  83. return true;
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement