Mailer Class
composer require initphp/mailer
- PHP 7.4 or higher
- MBString Extension
- Iconv Extension
- FileInfo Extension
$config = [
'mailType' => 'text' // or 'html'
'protocol' => 'smtp' // or 'mail' or 'sendmail'
'SMTPAuth' => true,
'SMTPHost' => 'smtp.gmail.com',
'SMTPUser' => '[email protected]',
'SMTPPass' => 'YourMailPassword',
'SMTPPort' => 587
];
$mailer = \InitPHP\Mailer\Mailer::newInstance($config);
$mailer->setFrom('[email protected]', 'Muhammet Şafak');
//$mailer->setTo('[email protected]');
//$mailer->setCC('[email protected]');
//$mailer->setBCC('[email protected]');
$mailer->setSubject('Mail Subject');
$mailer->setMessage('Mail Body Message');
$mailer->send();Creates a new mailer object and returns it.
public static function newInstance(?array $config = null): \InitPHP\Mailer\Mailerpublic function clear(bool $clearAttachments = false): selfpublic function setHeader(string $header, string $value): selfpublic function setFrom(string $from, string $name = '', ?string $returnPath = null): selfpublic function setReplyTo(string $replyTo, string $name = ''): selfpublic function setTo(string|array $to): selfpublic function setCC(string $cc): selfpublic function setBCC(string $bcc, ?int $limit = null): selfpublic function setSubject(string $subject): selfpublic function setMessage(string $body): selfpublic function setAttachmentCID(string $fileName): false|stringpublic function setAltMessage(string $str): selfpublic function setMailType(string $type = 'text'): self$type:textorhtml
public function setWordWrap(bool $wordWrap = true): selfpublic function setProtocol(string $protocol = 'mail'): self$protocol:mail,sendmailorsmtp
public function setPriority(int $n = 3): self$n: An integer between 1 and 5 inclusive.
public function setNewline(string $newLine = \PHP_EOL): selfpublic function setCRLF(string $CRLF = \PHP_EOL): selfpublic function attach(string|resource $file, string $disposition = '', ?string $newName = null, ?string $mime = null): false|selfpublic function send(bool $autoClear = true): boolpublic function printDebugger(array $include = ['headers', 'subject', 'body']): stringCopyright © 2022 MIT License