Created
June 29, 2011 03:03
-
-
Save gigo6000/1052884 to your computer and use it in GitHub Desktop.
Symfony2 console/command-line command to send email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace VayaFeliz\SiteBundle\Command; | |
use Symfony\Bundle\FrameworkBundle\Command\Command; | |
use Symfony\Component\Console\Input\InputArgument; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Input\InputOption; | |
use Symfony\Component\Console\Output\OutputInterface; | |
class SendEmailCommand extends Command | |
{ | |
protected function configure() | |
{ | |
$this | |
->setName('capifony:sendemail') | |
->setDescription('Send email') | |
->addArgument('emailfrom', InputArgument::REQUIRED, 'What\'s the sender email address?') | |
->addArgument('emailto', InputArgument::REQUIRED, 'What\'s the recipient email address?') | |
->addArgument('subject', InputArgument::REQUIRED, 'What\'s the email subject?') | |
; | |
} | |
protected function execute(InputInterface $input, OutputInterface $output) | |
{ | |
$emailfrom = $input->getArgument('emailfrom'); | |
$emailto = $input->getArgument('emailto'); | |
$subject = $input->getArgument('subject'); | |
if ($emailfrom && $emailto) { | |
$message = \Swift_Message::newInstance() | |
->setSubject($subject) | |
->setFrom($emailfrom) | |
->setTo($emailto) | |
->setBody('test') | |
; | |
$this->container->get('mailer')->send($message); | |
$text = "Email sent!"; | |
} else { | |
$text = 'Email not sent'; | |
} | |
$output->writeln($text); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://devtime.blogspot.com/2011/06/capifony-send-email-after-deployment.html