Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- require_once("lib/Smarty-3.1.3/Smarty.class.php");
- $smarty = new Smarty();
- $smarty->assign('title', 'Tytuł :D');
- $smarty -> display('indexAPMmail.tpl');
- use PHPMailer\PHPMailer\PHPMailer;
- require __DIR__ . '/vendor/autoload.php'; //Load composer's autoloader
- class APMmail {
- private $CharSet;
- private $isSMTP;
- private $Host;
- private $SMTPAuth;
- private $Username;
- private $Password;
- private $SMTPSecure;
- private $Port;
- private $mail;
- private $email_sender;
- private $email_recipient;
- private $subject;
- private $message;
- public function __construct($config) {
- $this->mail = new PHPMailer(true);
- $this->mail->isSMTP();
- $this->mail->CharSet = $config['CharSet'];
- $this->mail->Host = $config['Host'];
- $this->mail->SMTPAuth = $config['SMTPAuth'];
- $this->mail->Username = $config['Username'];
- $this->mail->Password = $config['Password'];
- $this->mail->SMTPSecure = $config['SMTPSecure'];
- $this->mail->Port = $config['Port'];
- }
- public function set_sender($emailSender){
- $this->email_sender = $emailSender;
- }
- public function get_sender()
- {
- return $this->email_sender;
- }
- public function set_Recipient($emailRecipient){
- $this->email_recipient = $emailRecipient;
- }
- public function set_Subject($subject){
- $this->subject = $subject;
- }
- public function set_Message($message){
- $this->message = $message;
- }
- public function send_mail(){
- $this->mail->setFrom($this->email_sender, $this->email_sender);
- $this->mail->addAddress($this->email_recipient, $this->email_recipient); // Add a recipient
- //$mail->addAddress('ellen@example.com'); // Name is optional
- $this->mail->addReplyTo($this->email_sender, $this->email_sender);
- //$mail->addCC('cc@example.com');
- //$mail->addBCC('bcc@example.com');
- //Attachments
- //$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
- //$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
- //Content
- $this->mail->isHTML(true); // Set email format to HTML
- $this->mail->Subject = $this->subject;
- $this->mail->Body = $this->message;
- $html = new \Html2Text\Html2Text($this->mail->Body);
- $this->mail->AltBody = $html->getText();
- if(!$this->mail->send()){
- return false;
- echo 'Mailer Error: ' . $this->mail->ErrorInfo;
- } else {
- return true;
- }
- }
- }
- if(isset($_POST['emailSender'])){
- $config = (object)[
- 'emailRecipient' => $_POST['emailRecipient'],
- 'subject' => $_POST['subject'],
- 'message' => $_POST['message'],
- ];}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement