{"id":241,"date":"2008-09-23T14:07:33","date_gmt":"2008-09-23T22:07:33","guid":{"rendered":"http:\/\/www.codebelay.com\/blog\/?p=241"},"modified":"2008-09-23T14:07:33","modified_gmt":"2008-09-23T22:07:33","slug":"symfony-has-a-swift-plugin-for-sending-gmail","status":"publish","type":"post","link":"https:\/\/www.codebelay.com\/blog\/2008\/09\/23\/symfony-has-a-swift-plugin-for-sending-gmail\/","title":{"rendered":"Symfony Has a Swift Plugin for Sending Gmail"},"content":{"rendered":"<p>It&#8217;s easy to send emails using your <a href=\"http:\/\/gmail.com\/\">gmail<\/a> account with the <a href=\"http:\/\/www.symfony-project.org\/plugins\/sfSwiftPlugin\">Swift Plugin<\/a>.<br \/>\nHere&#8217;s some sample code below<\/p>\n<pre>\r\n\r\n$to          = 'somebody@example.com';\r\n\r\n$htmlMessage = \"<b>OH HAI!<\/b>\";\r\n$textMessage = \"*OH HAI!*\";\r\n\r\n$connection = new Swift_Connection_SMTP(\r\n  sfConfig::get('app_email_smtp_server'),\r\n  sfConfig::get('app_email_smtp_port'), \r\n  Swift_Connection_SMTP::ENC_SSL\r\n);\r\n\r\n$connection->setUsername(sfConfig::get('app_email_username')); # gmail email\r\n$connection->setPassword(sfConfig::get('app_email_password')); # gmail password\r\n\r\n$mailer = new Swift($connection);\r\n$message = new Swift_Message(\"Your subject goes here. OH HAI!\");\r\n \r\n$message->attach(new Swift_Message_Part($htmlMessage, 'text\/html'));\r\n$message->attach(new Swift_Message_Part($textMessage, 'text\/plain'));\r\n \r\n\/\/ Send,\r\n\/\/ try and catch\r\ntry {\r\n  if (!$mailer->send($message, $to, sfConfig::get('app_email_username'))) {\r\n    throw new Exception('mailer error');\r\n  }\r\n} catch (Exception $e) {\r\n    sfContext::getInstance()->getLogger()->info(\r\n      \"Caught swift send error exception:\\n\" .  \r\n      $e->getMessage(). \" \".\r\n      $e->getFile() . \": Line \".\r\n      $e->getLine() . \"\\n\", $e->getTraceAsString(), \"\\n\"\r\n  );\r\n}\r\n          \r\n$mailer->disconnect();  \r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s easy to send emails using your gmail account with the Swift Plugin. Here&#8217;s some sample code below $to = &#8216;somebody@example.com&#8217;; $htmlMessage = &#8220;OH HAI!&#8221;; $textMessage = &#8220;*OH HAI!*&#8221;; $connection = new Swift_Connection_SMTP( sfConfig::get(&#8216;app_email_smtp_server&#8217;), sfConfig::get(&#8216;app_email_smtp_port&#8217;), Swift_Connection_SMTP::ENC_SSL ); $connection->setUsername(sfConfig::get(&#8216;app_email_username&#8217;)); # gmail email $connection->setPassword(sfConfig::get(&#8216;app_email_password&#8217;)); # gmail password $mailer = new Swift($connection); $message = new Swift_Message(&#8220;Your subject goes [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,56,33],"tags":[391,162,110],"class_list":["post-241","post","type-post","status-publish","format-standard","hentry","category-how-to","category-php","category-webapps","tag-php","tag-swift-plugin","tag-symfony"],"_links":{"self":[{"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/posts\/241","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/comments?post=241"}],"version-history":[{"count":0,"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/posts\/241\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/media?parent=241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/categories?post=241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/tags?post=241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}