Last Updated: July 04, 2017
·
1.068K
· azazqadir

Contact Form in Symfony with SwiftMailer

This is a tutorial about creating a contact form in Symfony using Form Builder. The contact form will be connected to the SwiftMailer Bundle so that the visitor could receive acknowledgment that the message has been successfully sent.

<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM

/**
* Contact
*
* @ORM\Table(name="contact")
* @ORM\Entity(repositoryClass="AppBundle\Repository\ContactRepository")
*/

class Contact
{
   /**
    * @var int
    *
    * @ORM\Column(name="id", type="integer")
    * @ORM\Id
    * @ORM\GeneratedValue(strategy="AUTO")
    */

   private $id;

   /**
    * @var string
    *
    * @ORM\Column(name="name", type="string", length=255)
    */

   private $name;

   /**
    * @var string
    *
    * @ORM\Column(name="email", type="string", length=255)
    */

   private $email;

   /**
    * @var string
    *
    * @ORM\Column(name="subject", type="string", length=255)
    */

   private $subject;

   /**
    * @var string
    *
    * @ORM\Column(name="message", type="string", length=255)
    */

   private $message;

   /**
    * Get id
    *
    * @return int
    */

   public function getId()

   {
       return $this->id;
   }

   /**
    * Set name
    *
    * @param string $name
    *
    * @return Contact
    */

   public function setName($name)
   {
       $this->name = $name;
       return $this;
   }

   /**
    * Get name
    *
    * @return string
    */

   public function getName()
   {
       return $this->name;
   }

   /**
    * Set email
    *
    * @param string $email
    *
    * @return Contact
    */

   public function setEmail($email)
   {
       $this->email = $email;
       return $this;
   }

   /**
    * Get email
    *
    * @return string
    */

   public function getEmail()
   {
       return $this->email;
   }

   /**
    * Set subject
    *
    * @param string $subject
    *
    * @return Contact
    */

   public function setSubject($subject)
   {
       $this->subject = $subject;
       return $this;
   }

   /**
    * Get subject
    *
    * @return string
    */

   public function getSubject()
   {
       return $this->subject;
   }

   /**
    * Set message
    *
    * @param string $message
    *
    * @return Contact
    */

   public function setMessage($message)
   {
       $this->message = $message;
       return $this;
   }

   /**
    * Get message
    *
    * @return string
    */

   public function getMessage()

   {
       return $this->message;
   }

}

Source: https://www.cloudways.com/blog/create-contact-form-symfony-with-swiftmailer/

Are there any alternative to swiftmailer?