Skip to content

Instantly share code, notes, and snippets.

@harmlessprince
Created October 9, 2021 10:32
Show Gist options
  • Save harmlessprince/aff0fa7f425d0d2bb2553f33786f5004 to your computer and use it in GitHub Desktop.
Save harmlessprince/aff0fa7f425d0d2bb2553f33786f5004 to your computer and use it in GitHub Desktop.
<?php
class SendMail
{
private $sendTo;
private $from;
private $name;
private $subject;
private $message;
private $headers;
private $attachment;
public function __construct($sendTo, $from, $name, $subject, $message, $attachment = null)
{
$this->sendTo = $sendTo;
$this->from = $from;
$this->name = $name;
$this->subject = $subject;
$this->message = $message;
$this->attachment = $attachment;
}
/**
* Get the value of sendTo
*/
public function getSendTo()
{
return $this->sendTo;
}
/**
* Set the value of sendTo
*
* @return self
*/
public function setSendTo($sendTo)
{
$this->sendTo = $sendTo;
return $this;
}
/**
* Get the value of from
*/
public function getFrom()
{
return $this->from;
}
/**
* Set the value of from
*
* @return self
*/
public function setFrom($from)
{
$this->from = $from;
return $this;
}
/**
* Get the value of name
*/
public function getName()
{
return $this->name;
}
/**
* Set the value of name
*
* @return self
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get the value of subject
*/
public function getSubject()
{
return $this->subject;
}
/**
* Set the value of subject
*
* @return self
*/
public function setSubject($subject)
{
$this->subject = $subject;
return $this;
}
/**
* Get the value of message
*/
public function getMessage()
{
return $this->message;
}
/**
* Set the value of message
*
* @return self
*/
public function setMessage($message)
{
$this->message = $message;
return $this;
}
public function sendMail()
{
// Header for sender info
$headers = "From: $this->name" . " <" . $this->from . ">";
// Boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
$this->setHeaders($headers);
mail($this->sendTo, $this->subject, $this->message, $this->headers);
}
public function redirect($path)
{
//Telling the browser where to go.
header("Location: $path");
}
/**
* Get the value of headers
*/
public function getHeaders()
{
return $this->headers;
}
/**
* Set the value of headers
*
* @return self
*/
public function setHeaders($headers)
{
$this->headers = $headers;
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment