Commit 62a31c0f authored by Igor Wiedler's avatar Igor Wiedler

[docs] rewrite usage POST example to not use Swiftmailer

parent 3c92b812
...@@ -142,31 +142,24 @@ Example POST route ...@@ -142,31 +142,24 @@ Example POST route
~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~
POST routes signify the creation of a resource. An example for this is a POST routes signify the creation of a resource. An example for this is a
feedback form. We will use `Swift Mailer feedback form. We will use the ``mail`` function to send an e-mail::
<http://swiftmailer.org/>`_ and assume a copy of it to be present in the
``vendor/swiftmailer`` directory::
require_once __DIR__.'/vendor/swiftmailer/lib/swift_required.php';
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
$app->post('/feedback', function (Request $request) { $app->post('/feedback', function (Request $request) {
$message = \Swift_Message::newInstance() $message = $request->get('message');
->setSubject('[YourSite] Feedback') mail('feedback@yoursite.com', '[YourSite] Feedback', $message);
->setFrom(array('noreply@yoursite.com'))
->setTo(array('feedback@yoursite.com'))
->setBody($request->get('message'));
$transport = \Swift_MailTransport::newInstance();
$mailer = \Swift_Mailer::newInstance($transport);
$mailer->send($message);
return new Response('Thank you for your feedback!', 201); return new Response('Thank you for your feedback!', 201);
}); });
It is pretty straight forward. We include the Swift Mailer library, It is pretty straightforward.
set up a message and send that message.
.. note::
There is a `SwiftmailerExtension <extensions/swiftmailer>` included
that you can use instead of ``mail()``.
The current ``request`` is automatically injected by Silex to the Closure The current ``request`` is automatically injected by Silex to the Closure
thanks to the type hinting. It is an instance of `Request thanks to the type hinting. It is an instance of `Request
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment