Call Mail System via PHP
In this tutorial, you will learn about the parameters of BlueSMTPMail() and BlueFormSend(), set up internal or external sending, and find out how to handle attachments, HTML content, and send logs.
Objective of the Tutorial
Note: This tutorial is aimed at developers and shows how to directly call the integrated mail system of the bluetronix CMS via PHP.
The bluetronix CMS provides central PHP functions for sending emails.
This means that SMTP connections, mail accounts, and basic sending functions do not need to be reprogrammed for each individual PHP script.
The following function is available for direct email and newsletter sending:
BlueSMTPMail($MailType,$MailAccount,$SMTPType,$From,$To,$NewsletterTo,$Subject,$TextContent,$HTMLContent,$Attachments,$EmbedImages,$MailPlaceholderReplacement,$FormEntry);
Additionally, the following function is available for sending form emails:
BlueFormSend($SMTPType,$SendMail,$SendSubject,$CopyToCustomer,$TextToCustomer,$FormArchive,$FormID,$SendTo);
BlueSMTPMail()
With BlueSMTPMail(), standard emails and newsletters can be sent through the central mail system of the bluetronix CMS.
The function call is:
BlueSMTPMail(
$MailType,
$MailAccount,
$SMTPType,
$From,
$To,
$NewsletterTo,
$Subject,
$TextContent,
$HTMLContent,
$Attachments,
$EmbedImages,
$MailPlaceholderReplacement,
$FormEntry
);
$MailType
Determines which type of email should be sent.
Possible values:
Mail
Newsletter
Example:
$MailType = "Mail";
or:
$MailType = "Newsletter";
$MailAccount
$MailAccount determines the email account whose SMTP settings will be used.
This value loads the corresponding SMTP configuration data from the CMS database tables.
Which configuration is used additionally depends on $SMTPType.
$SMTPType
Determines whether an internal or external email account is used.
Possible values:
Intern
Extern
Internal
When:
$SMTPType = "Intern";
an email account is used that has been set up directly in the bluetronix CMS.
The accounts are located at:
Email → Accounts
The sender address used under $From must be present as an account there.
External
When:
$SMTPType = "Extern";
uses external SMTP access data.
These are managed in the CMS under:
Email → Server - Extern
The sender address used under $From must be properly configured there.
The sender address used in $From must be configured accordingly.
$From
Contains the email address of the sender.
Example:
$From = "info@example.com";
The email address must match the selected SMTP configuration.
$To
Contains the email address of the recipient of a regular email.
Example:
$To = "customer@example.com";
In a regular email send, this variable is used as the recipient.
$NewsletterTo
$NewsletterTo is used for sending newsletters.
The variable contains multiple email addresses as text. Each email address is separated by a line break.
Example:
$NewsletterTo = "customer1@example.com\ncustomer2@example.com\ncustomer3@example.com";
$Subject
Contains the subject of the email.
Example:
$Subject = "Welcome to our website";
$TextContent
Contains the plain text part of the email.
This part can be used by email programs that do not display HTML emails.
Example:
$TextContent = "Thank you for your request.";
$HTMLContent
Contains the HTML part of the email.
Example:
$HTMLContent = "<h1>Thank you</h1><p>Thank you for your request.</p>";
This allows formatted emails to be sent with headings, texts, links, images, and other HTML elements.
$Attachments
Files can be attached to the email using $Attachments.
The files are specified by their path within the website.
Example:
$Attachments = "/bx_doc/Intro.pdf";
For multiple attachments, the individual file paths are separated by a line break.
Example:
$Attachments = "/bx_doc/Intro.pdf\n/bx_doc/PriceList.pdf";
$EmbedImages
With $EmbedImages, it can be specified whether images should be embedded directly in the email.
Example:
$EmbedImages = "ja";
If the option is enabled, the images used within the HTML email are integrated directly into the email and not only loaded via external URLs.
This allows the images to be directly available within the email for the recipient without needing to be loaded separately from the web server.
$MailPlaceholderReplacement
With $MailPlaceholderReplacement, placeholders within:
$TextContent
$HTMLContent
can be replaced with individual values.
The principle is:
Search
↓
Replace
This allows for personalized content to be generated within an email.
Typical use cases are:
- Name des Empfängers
- Kundennummer
- Bestellnummer
- individuelle Links
- weitere dynamische Inhalte
$FormEntry
With $FormEntry, it can be specified whether the dispatch should also be saved in the form archive.
When:
$FormEntry = "JA";
an entry in the database table will also be created:
00_form
saved.
This allows the sending to be documented simultaneously as a form or archive entry.
Example: Sending a regular email
The following example sends a regular HTML and text email via an internal mail account.
$MailType = "Mail";
$MailAccount = "info@example.com";
$SMTPType = "Intern";
$From = "info@example.com";
$To = "customer@example.com";
$NewsletterTo = "";
$Subject = "Your request";
$TextContent = "Thank you for your request.";
$HTMLContent = "<h1>Thank you</h1><p>Thank you for your request.</p>";
$Attachments = "/bx_doc/Intro.pdf";
$EmbedImages = "ja";
$MailPlaceholderReplacement = "";
$FormEntry = "NEIN";
BlueSMTPMail($MailType,$MailAccount,$SMTPType,$From,$To,$NewsletterTo,$Subject,$TextContent,$HTMLContent,$Attachments,$EmbedImages,$MailPlaceholderReplacement,$FormEntry);
The simplified procedure is as follows:
PHP
↓
BlueSMTPMail()
↓
internen Mail-Account laden
↓
SMTP-Verbindung verwenden
↓
E-Mail erzeugen
↓
E-Mail versenden
↓
MailCache-Eintrag erzeugen
Example: Sending a newsletter
For a newsletter, set $MailType to:
Newsletter
.
The recipients are then passed via $NewsletterTo.
$MailType = "Newsletter";
$MailAccount = "newsletter@example.com";
$SMTPType = "Intern";
$From = "newsletter@example.com";
$To = "";
$NewsletterTo = "customer1@example.com\ncustomer2@example.com\ncustomer3@example.com";
$Subject = "Our latest news";
$TextContent = "Discover our latest news and products.";
$HTMLContent = "<h1>Our latest news</h1><p>Discover our latest news and products.</p>";
$Attachments = "";
$EmbedImages = "ja";
$MailPlaceholderReplacement = "";
$FormEntry = "NEIN";
BlueSMTPMail($MailType,$MailAccount,$SMTPType,$From,$To,$NewsletterTo,$Subject,$TextContent,$HTMLContent,$Attachments,$EmbedImages,$MailPlaceholderReplacement,$FormEntry);
The individual newsletter recipients are separated by line breaks within $NewsletterTo.
Use external SMTP connection
If an external mail server is to be used, then:
$SMTPType = "Extern";
.
The SMTP access data must be set up beforehand at:
Email → Server - Extern
.
Example:
$SMTPType = "Extern";
$From = "mail@external-domain.com";
$MailAccount = "mail@external-domain.com";
BlueFormSend()
In addition to direct email sending, the function is available:
BlueFormSend($SMTPType,$SendMail,$SendSubject,$CopyToCustomer,$TextToCustomer,$FormArchive,$FormID,$SendTo);
.
This function is specifically intended for email sending in connection with CMS forms.
The variables are already fully in English.
Parameters of BlueFormSend()
| Variable | Usage |
|---|---|
$SMTPType |
Select internal or external SMTP sending. |
$SendMail |
Controls the mail sending of the form. |
$SendSubject |
Subject of the form email. |
$CopyToCustomer |
Controls whether the customer receives a copy. |
| $TextToCustomer | Text for the message to the customer |
| $FormArchive | Controls the archiving of the form |
| $FormID | ID of the respective form |
| $SendTo | Recipient of the form email |
MailCache
Each call to BlueSMTPMail() additionally creates an entry in the database table:
00_MailCache
This table can be used to track the status of the email sending.
It can be checked there, for example, whether an email was successfully processed or sent.
The MailCache entries are for:
1 Woche
saved.
Typical process of mail sending
PHP-Skript
↓
BlueSMTPMail()
↓
MailType prüfen
↓
MailAccount auswählen
↓
SMTPType prüfen
↓
SMTP-Konfiguration laden
↓
Empfänger bestimmen
↓
Text- und HTML-Inhalt erstellen
↓
Platzhalter ersetzen
↓
Anhänge hinzufügen
↓
Bilder gegebenenfalls einbetten
↓
E-Mail versenden
↓
00_MailCache aktualisieren
↓
optional 00_form speichern
Overview of BlueSMTPMail parameters
| Variable | Meaning |
|---|---|
| $MailType | Mail or newsletter |
| $MailAccount | Mail account to be used |
$SMTPType |
Internal or external |
| $From | Sender address |
| $To | Recipient of a regular email |
| $NewsletterTo | Newsletter recipient, separated by line breaks |
| $Subject | Email Subject |
$TextContent |
Text part of the email |
$HTMLContent |
HTML part of the email |
$Attachments |
File paths of attachments |
$EmbedImages |
Integrate images directly into the email |
$MailPlaceholderReplacement |
Replace placeholders within the email content |
$FormEntry |
Create optional entry in 00_form |
Zusammenfassung
The central mail system of the bluetronix CMS can be called directly from your own PHP code.
Für normalen E-Mail- und Newsletter-Versand wird verwendet:
BlueSMTPMail($MailType,$MailAccount,$SMTPType,$From,$To,$NewsletterTo,$Subject,$TextContent,$HTMLContent,$Attachments,$EmbedImages,$MailPlaceholderReplacement,$FormEntry);
For CMS forms, the following is also available:
Internal
→ Email → Accounts
or:
Every email sent is also tracked via:
This allows developers to use the existing mail system of the bluetronix CMS directly from their PHP scripts without having to implement the complete SMTP logic themselves.
What functions does the central mail system provide for PHP?
For regular emails and newsletters, you use BlueSMTPMail(). For sending in connection with CMS forms, BlueFormSend() is also available.
Where can I find the internal email accounts?
Internal mail accounts are set up under Email → Accounts. For their sending, set $SMTPType to Intern. The sender address must belong to a configured account.
How do I use an external SMTP server?
Set up the access data under Email → Server - External and use $SMTPType = "External";. The sender address must match the chosen configuration.
What is the difference between mail and newsletter?
]}BlueFormSend($SMTPType,$SendMail,$SendSubject,$CopyToCustomer,$TextToCustomer,$FormArchive,$FormID,$SendTo);
Die SMTP-Konfiguration kann entweder über:Intern → Email → Accounts or:
Extern
→ Email → Server - Extern
erfolgen.Every email sent will also go through:
00_MailCache
protokolliert. Die entsprechenden Cache-Einträge bleiben eine Woche erhalten.This allows developers to use the existing mail system of the bluetronix CMS directly from their own PHP scripts without having to implement the entire SMTP logic themselves.
FAQ
what customers often ask us
What functions does the central mail system provide for PHP?
For regular emails and newsletters, use BlueSMTPMail(). For sending in connection with CMS forms, BlueFormSend() is also available.
Where can I find the internal email accounts?
Internal email accounts are set up under Email → Accounts. For sending, set $SMTPType to Intern. The sender address must belong to a configured account.
How do I use an external SMTP server?
Set up the access data under Email → Server - Extern and use $SMTPType = "Extern";. The sender address must match the chosen configuration.
What is the difference between mail and newsletter?
With $MailType = "Mail";, a normal email is sent to the recipient listed in $To. For a newsletter, set $MailType = "Newsletter"; and pass the recipients via $NewsletterTo.
How do I pass multiple newsletter recipients?
Enter the addresses in $NewsletterTo and separate each email address with a line break.
Can I send text and HTML in the same email?
Yes. The plain text is in $TextContent, while you pass the formatted HTML message via $HTMLContent.
How do I add attachments to an email?
Use $Attachments to pass file paths within the website. For multiple attachments, separate the paths with line breaks.
How can I embed images directly in an email?
The template uses $EmbedImages = "yes"; for this. This embeds the images used within the HTML message directly as per the described CMS function.
What is MailPlaceholderReplacement used for?
This allows you to replace placeholders in text and HTML content with individual values such as names, order numbers, or personal links. The template describes the search-and-replace principle, but not a specific passing format.
How do I additionally archive the sending as a form entry?
Set the value $FormEntry = "YES"; in BlueSMTPMail(). According to the template, an entry will then be saved in 00_form.
Where can I check the sending status?
The template describes the table 00_MailCache for this purpose. The shipping entries created there are stored for a week. A processing entry alone is not additional proof of delivery to the recipient.
When do I use BlueFormSend()?
BlueFormSend() is intended for sending emails with CMS forms. Parameters include, among others, dispatch control, subject, customer copy, form archive, and form ID.