Configuration
You can control the configurations from the resources\settings\.env.
use Kiaan\Mail.
# Email
Email_email=email@example.com
Email_name=
Email_host=smtp.mailtrap.io
Email_username=
Email_password=
Email_port=465
Email_protocol=
To
Set the receiving user for e-mail (Set e-mail and name).
Mail::to("to@email.com", "Hassan")
Or set e-mail only.
Mail::to("to@email.com")
Can multiply.
Mail::to("hassan@email.com", "Hassan")
->to("mohammed@email.com", "Mohammed")
From
Set the sender.
Mail::from("from@email.com", "Hassan")
Subject
Set subject of e-mail.
Mail::subject("Subject")
Message
Set message of e-mail.
Mail::message("Hello Hassan")
You can include HTML in the message
Mail::message("Hello <b>Hassan</b>")
->html()
You can use the email message content page template using the page() method.
CC & BCC and reply
CC stands for “Carbon Copy” and BCC stands for “Blind Carbon Copy” for email.
Mail::from("from@email.com", "Ahmed")
->to("to@email.com", "Hassan")
->message("Hello Hassan")
->cc('steve@example.com', 'Steve Jobs') // multiple possible
->bcc('bill@example.com', 'Bill Gates') // multiple possible
->reply('replay@example.com', 'replay Gates') // multiple possible
CC & BCC and reply can multiple possible.
Attachments
You can attach files to mail.
Mail::attach("public/1.jpg")
->attach("public/2.jpg")
Attachments can multiple possible.
Submit mail
You can call the send() method to send the email.
$mail = Mail::to("to@email.com", "Hassan")
->reply("reply@email.com")
->cc("cc@email.com")
->bcc("bcc@email.com")
->subject("subject")
->message("message")
->attach("public/qwe.png");
//->message("<b>message<b>")
//->html();
if($mail->send()){
echo 'Success!';
} else {
echo 'An error occurred.';
}
Mailer
You can selected mailer driver using mailer() method.
Mail::mailer(); // Mail server function
Mail::mailer("mail"); // Mail server function
Mail::mailer("smtp"); // SMTP server
SMTP
The Simple Mail Transfer Protocol (SMTP) is an internet standard communication protocol for electronic mail transmission.
You can call the smtp() method to SMTP.
$mail = Mail::smtp()
->to("to@email.com", "Hassan")
->reply("reply@email.com")
->cc("cc@email.com")
->bcc("bcc@email.com")
->subject("subject")
->attach("public/qwe.png")
->message("<b>message<b>")
->html();
if($mail->send()){
echo 'Success!';
} else {
echo 'An error occurred.';
}