Deprecated: Constant E_STRICT is deprecated since 8.4, the error level was removed in /home/autoperi/_SUBDOMAINS_/mail-service.devrise.rs/vendor/symfony/error-handler/ErrorHandler.php on line 58

Deprecated: Constant E_STRICT is deprecated since 8.4, the error level was removed in /home/autoperi/_SUBDOMAINS_/mail-service.devrise.rs/vendor/symfony/error-handler/ErrorHandler.php on line 76
Mail Service Documentation

Quick Start

Last updated: Dec 15th, 2019

Mail Service

Mail service is small Symfony application / service which uses swift mailer bundle for sending mails.

Symfony provides a mailer feature based on the popular Swift Mailer library via the SwiftMailerBundle. This mailer supports sending messages with your own mail servers as well as using popular email providers like Mandrill, SendGrid, and Amazon SES.

Symfony's Mailer & Mime components form a powerful system for creating and sending emails - complete with support for multipart messages, Twig, CSS inlining, file attachments and a lot more.

When we are introduced to the theory it's time to move on to the practical part

SwiftMailer

Usage

Introduction to the task

  • Route: Email send
  • Method: POST
  • POST is used to send data to a server to create/update a resource.
  • Schema: https
  • HyperText Transfer Protocol Secure (HTTPS) is an extension of the Hypertext Transfer Protocol (HTTP). It is used for secure communication over a computer network, and is widely used on the Internet.
  • Payload:
    • name - Sender full name
    • email - Sender email address
    • subject - Email subject

      Last 3 payloads are paramount to the functionality of the service itself

    • sendTo- Email must be valid in order for the message itself to reach user
    • sendfrom - Is the email of the person sending the message (i.e. your email)
    • message - Text that you want to send to someone

Code

HTML Code

Before entering the code, you need to open the body tag in which it will be implemented.

It is necessary to create a form, which will have the appropriate inputs to send the email.

The most important thing is to indicate to whom the e-mail is sent and from whom it is received, if those inputs are not set, an error will occur, i.e. the e-mail will not be sent.


    <div class="contact" id="contactForm" action="https://contact-controller.bet.org.rs/email/send" method="POST">
        <form id="contactForm" action="https://contact-controller.bet.org.rs/email/send" method="POST">
    <div class="row">
        <div class="col-md-4">
            <input type="text" id="name" name="name" placeholder="Full Name">
        </div>
        <div class="col-md-4">
            <input type="text" id="subject" name="subject" placeholder="Subject">
        </div>
        <div class="col-md-4">
            <input type="text" id="email" name="email" placeholder="E-mail">
            <input type="hidden" id="sendto" name="sendto" value="your@email.com">
            <input type="hidden" id="sendfrom" name="sendfrom" value="contact@somedomain.rs">
        </div>
    </div>
            <textarea placeholder="Message" id="message" name="message" rows="8" > </textarea>
            <button class="btn-ghost pull-right" type="submit" > Send </button>
        <form>
    </div>

JavaScript Code

Brief explanation of JS

JavaScript is a script language that you can use for front-end development. When the name JavaScript is used in the context of sending emails Jqueri is the first thing that comes to mind.

The short answer is that you can't send mail using JavaScript alone. You'd need a server-side handler to connect with the SMTP server to actually send the mail. There are many simple mail scripts online, such as this one.

For sending an email in js is necessary to:

  • To load js library, in this case it is jquery(Click here for CDN,and how to implement it) CDN link should be placed at the end of the body tag
  • Use jquery functon to send email (use POST to "submit" data)
  • If conditions - in case of error we can see what is the problem as well as if an email is sent to receive notification of successful sending
  • 
        $('#contactForm').on('submit',function(e){
        e.preventDefault();
    
        var $action = $(this).prop('action');
        var $data = $(this).serialize();
        var $this = $(this);
    
        $this.prevAll('.alert').remove();
    
        $.post( $action, $data, function( response ) {
    
            if( response === 'error' ){
                $this.before( '
    Došlo je do greške.
    Molimo pokušajte ponovo kasnije!
    ' ); } if( response === 'success' ){ $this.before( '
    Hvala Vam na poslatoj poruci.
    Odgovorićemo Vam u najkraćem mogućem roku!
    ' ); $this.find('input, textarea').val(''); } }, "json"); });