Almost any business system comes to the point where an email needs to be sent, either through a trigger when a specific event in the database happens or on demand through a service.
Hint: SMTP stands for Simple Mail Transfer Protocol.
The main difficulty in this matter is to get the parameters for the SMTP connection correct. Topincs provides the PHP function email which accepts the SMTP connection parameters. You should only define this once in your system, thus you need to create a wrapper handling it.
Santa Claus has heard of email and is intrigued by the seemingly limitless possibilities this communication technology has to offer. He wants to use it extensively to reach new levels of productivity in his enterprise. The elves too are curious and dream of longer nap time.
API reference
Hint: Your email client uses your SMTP connection parameters to send emails. That is the best place to start looking for them.
<?php
function santa_mail($to, $subject, $text) {
email(
to: $to,
subject: $subject,
text: $text,
from: "Santa Claus <santa@xmas.org>",
config: [
"smtp" => [
"username" => "santa",
"password" => "H0H0",
"host" => "smtp.xmas.org",
"port" => "465",
"security" => "ssl",
// "debug" => true
]
]
);
}
When you want to add an attachment to an email use the respective parameter in the email function. You can add temporary files using its path or Topincs files by passing a file tobject.
API reference
<?php
// Attaching one Topincs file:
$price_doc = Tobject::get(1234);
email(
attachment: $price_doc,
...
);
// Attaching one temporary file. Many times you will
// call a service to create the file:
$tmp_file = tmp_file(call("offer.pdf", ["offer" => $offer]));
email(
attachment: $tmp_file,
...
);
// Above will result in a random filename with no extension.
// Attaching with name is therefore better:
email(
attachment: ["name"=> "Offer.pdf", "path" => $tmp_file],
...
);
// Attaching multiple files, any of the above in an array:
email(
attachment: [
$price_doc,
$tmp_file,
["name" => "Offer.pdf, "path" => $path]
],
...
);
This page cannot be displayed in your browser. Use Firefox, Opera, Safari, or Chrome instead.
Saving …