Work with e-mail based on a plug-in PHPMailer. Connection DIAFAN.CMS and plugin provides a function send_mail, described in the file includes/mail.php. In CMS this function is mainly used to notify users of any action, such as purchasing a product (modules/cart/cart.action.php).


boolean send_mail (string|array $recipient, string $subject, string $body, [string $from = '']) – Отправляет электронное письмо.

  • string|array $recipient: получатель/получатели
  • string $subject: тема письма
  • string $body: содержание письма
  • string $from: адрес отправителя


// send Vasya a notice on the mailbox each time you view it product
// file modules/shop/shop.model.php method id()
$sent = send_mail(
"", // recipient
"Someone watching your product on the website ".BASE_PATH_HREF, // subject
"Hey, someone has come to your product page
.BASE_PATH_HREF.$this->diafan->_route->current_link(), // message
); // === true, if a letter has been sent successfully


For example, the store sell button "Tell a friend", when clicked, a form appears with the input field email.


Create file modules/shop/views/shop.view.email_form.php

<div class="modal-wrap" id="shop-modal-wrap">
   <div class="modal" id="shop-modal">
       <div class="window" style="width:300px">
           <div class="window_title">
               Send to frend
           <form method="POST" enctype="multipart/form-data" action="" class="ajax">
               <input type="hidden" name="module" value="shop">
               <input type="hidden" name="action" value="mail">
               <input type="hidden" name="good_id" value="<?php echo $result['id'];?>">
               <table style="width:300px">
                           <input type="email" name="mail">
                           <div class="errors error_mail" style="display:none"></div>
               <input type="submit" value="Send">
           <div class="errors error"></div>
           <div class="modal-close close"></div>

In the file modules/shop/views/ write:

$this->get('email_form', 'shop', $result);

In controller modules/shop/shop.php add:

switch ($_POST['action'])
// ...

Now add handler of POST-requests in the file modules/shop/shop.action.php:

public function send_friends()
    if (empty(
$this->result['errors']['mail'] = 'Please, enter e-mail.';
$this->valid_email($_POST['mail'], "mail");
$row = DB::query_fetch_array("SELECT [name], site_id, cat_id, id FROM {shop} WHERE id=%d LIMIT 1", $_POST['good_id']);
    if (empty(
$this->result['errors'][0] = 'Error.';

    if (

$row['link'] = BASE_PATH_HREF.$this->diafan->_route->link($row["site_id"], "shop", $row["id"]);

$subject = "I recommend to watch";
$message = 'Hello! Your friend recommends you to view <a href="'.$row['link'].'">'.$row['name'].'</a>.';
$from_mail = $this->diafan->configmodules("emailconf", 'shop') ? $this->diafan->configmodules("email", 'shop') : '';

$this->result['errors'][0] = send_mail($_POST['mail'], $subject, $message, $from_mail) ? 'Sent' : 'Error';