Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • PHP Challenge PHP Challenge
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
  • Deployments
    • Deployments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Infrastructure Registry
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • Jobsity
  • PHP ChallengePHP Challenge
  • Wiki
  • Usage of the Mailer service (SwiftMailer)

Last edited by Jobsity Jun 01, 2021
Page history

Usage of the Mailer service (SwiftMailer)

We have implemented SwiftMailer for you in this codebase. To use it, you may refer to this example.


// As an example we can use the Mailer service in a Controller.
// We can inject the service from the class Constructor.
class HelloController
{
    /**
     * @var Swift_Mailer
     */
    protected $mailer;

    /**
     * @param Swift_Mailer $mailer
     */
    public function __construct(Swift_Mailer $mailer)
    {
        $this->mailer = $mailer;
    }
}

// Then we can just call the Mailer from any Controller method.
$message = (new Swift_Message('Hello from PHP Challenge'))
    ->setFrom(['phpchallenge@jobsity.io' => 'PHP Challenge'])
    ->setTo(['user@domain.org'])
    ->setBody('SwiftMailer is awesome!.');

// Later just do the actual email sending.
$this->mailer->send($message);

For more information about SwiftMailer, please visit:

https://swiftmailer.symfony.com/docs/introduction.html

For additional information about the Dependency Container, please refer to:

https://www.slimframework.com/docs/v4/concepts/di.html

Clone repository
  • PHP Challenge Instructions
  • Usage of the Mailer service (SwiftMailer)
  • Using RabbitMQ with Slim Framework
  • Home