Sending email
In MV, mail is initially sent via the mail function, but you can configure sending via SMTP. In the core folder, there is a class file email.class.php, which contains the class and the send() method for sending messages. Messages are sent using the PHPMailer library.
SMTP configuration and the sender's address are located in the .env file
//General view of the method
Email::send($recipient, $subject, $message[, $headers, $attachments]);
//Sending a message
Email::send('test@domain.com', 'Good news', 'Text of the good news');
//Multiple recipients
$recipients = ['first@domain.com', 'second@domain.com', 'third@domain.com'];
$recipients = implode(',', $recipients);
$message = 'Long text of good news ...';
Email::send($recipients, 'Good news', $message);
//Additional headers
$headers = ['From' => 'info@mysite.com'];
Email::send($recipients, 'Good news', 'Text of good news', $headers);
//Sending email with attachment
$files = [Registry::get('IncludePath').'userfiles/files/price.pdf'];
Email::send($email, 'Our price list', $message, [], $files);
Signature and formatting of letters
The letter template and its CSS styles are in the customs/emais/default.php file, before sending the letter the template can be changed using the Email::setTemplate('template_name') method. The template_name.php file should also be in the customs/emails/ folder.
When forming the text of the letter using HTML tags, try not to make nested constructions, use simple techniques.
Important points
- Letters are sent in utf-8 encoding.
- The subject of the letter is also encoded in utf-8.
- The content type of the letter is text/html.
- Additional headers can be passed in the optional $headers parameter as an associated array.
- The sender's return address is set in the .env file, EMAIL_FROM setting.
Previous section
Redirects and http