{"id":18929482,"url":"https://github.com/thecodingmachine/utils.mailer.swift-mail-service","last_synced_at":"2026-03-16T14:30:18.458Z","repository":{"id":17777038,"uuid":"20645461","full_name":"thecodingmachine/utils.mailer.swift-mail-service","owner":"thecodingmachine","description":"This package contains a mailer for the Mouf framework that uses a SMTP server to send mail. The package is a wrapper around the Swift_Mailer class of the Swift library.","archived":false,"fork":false,"pushed_at":"2018-11-15T22:46:21.000Z","size":83,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":15,"default_branch":"1.0","last_synced_at":"2025-02-16T12:30:31.258Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thecodingmachine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-06-09T12:18:46.000Z","updated_at":"2018-11-15T22:46:22.000Z","dependencies_parsed_at":"2022-09-09T04:50:40.826Z","dependency_job_id":null,"html_url":"https://github.com/thecodingmachine/utils.mailer.swift-mail-service","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Futils.mailer.swift-mail-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Futils.mailer.swift-mail-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Futils.mailer.swift-mail-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Futils.mailer.swift-mail-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thecodingmachine","download_url":"https://codeload.github.com/thecodingmachine/utils.mailer.swift-mail-service/tar.gz/refs/heads/1.0","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239927823,"owners_count":19719835,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T11:32:57.383Z","updated_at":"2026-03-16T14:30:18.409Z","avatar_url":"https://github.com/thecodingmachine.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"The SwiftMailService\n===================\n\nThe `SwiftMailService` is a wrapper of the Swift library for the Mouf PHP framework.\nIt is used to send mails using a SMTP mail server.\n\nThe `SwiftMailService` is designed to be simple to use. Behind the scene, the \u003ccode\u003eSwiftMailService\u003c/code\u003e\nis using the more complex (and more powerful) Swift Mailer mail service.\n\nInstall\n-------\nThis package is part of the [Mouf PHP framework](http://mouf-php.com). As such, it comes with a nice graphical installer.\n\n![Install screen](doc/images/smtp_install.png)\n\nYou can configure the settings to connect to your SMTP server.\n\nThere is one compulsory parameter: \u003cb\u003ehost\u003c/b\u003e, which is the address of the server.\n\nBy default, on Linux systems, it is likely you will use the local mail server (host=127.0.0.1). You will have a \"sendmail\" or \"postfix\" server installed\non your machine.\nIf you are performing your developments on a Windows machine, it is quite likely that you will not have an SMTP server on your machine. You will \ntherefore have to use a remote server. To access the remote server, you will certainly have to use login/passwords, etc...\n\nWhen this package is installed, it will create 2 instances:\n\n- a `swiftMailService` that implements Mouf's `MailServiceInterface`\n- a `swiftMailer` that is the classic Swift mailer.\n\n\u003cdiv class=\"alert alert-info\"\u003eNote: nothing prevents you from creating several instances of the SwiftMailService class\nwith different parameters (in the rare case you have an application that needs to connect to several SMTP servers).\u003c/div\u003e\n\nAfter installation, you will see that a number of constants have been added to your `config.php` file.\nWhen deploying on other servers, you can of course change those constants to adapt to the settings of the server.\n\nWhat? 2 instances?\n------------------\n\nThere are both a `swiftMailService` and a `swiftMailer`. Which should you use?\n\nWell it depends...\n\n- `swiftMailService` implements Mouf's `MailServiceInterface`. This is a simple interface to create mails easily.\n  Use it if you have simple needs. If you use this instance, you will be able to easily replace your Swift mailer\n  with any other mailer compatible with the `MailServiceInterface`, like the `SmtpMailService` (that uses\n  ZendMail as a backend), or the DBMailService (that stores mails in database instead of sending them).\n  \n- `swiftMailer` is great if you want a greater control over your mails, or if you are already used to using\n  Swift directly. It is also greatly documented over the web.\n\nTip: using your gmail account to send mails\n-------------------------------------------\n\nIn a development environment, it can be useful to use you gmail account. Here are the settings:\n\n- host =\u0026gt; 'smtp.gmail.com'\n- ssl =\u0026gt; 'tls'\n- port =\u0026gt; 587\n- auth =\u0026gt; 'login'\n- username =\u003e \u003cem\u003eYour gmail mail address\u003c/em\u003e\n- password =\u003e \u003cem\u003eYour password\u003c/em\u003e\n\nExample use\n-----------\n\nBelow is a sample code you can use to send a mail.\n\n```php\nuse Mouf\\Utils\\Mailer\\Mail;\nuse Mouf\\Utils\\Mailer\\SwiftMailService;\n\n// First, let's create the mail object\n$mail = new Mail();\n$mail-\u003esetTitle(\"My mail\");\n$mail-\u003esetBodyText(\"This is my mail!\");\n$mail-\u003esetBodyHtml(\"This is my \u0026lt;b\u0026gt;mail\u0026lt;/b\u0026gt;!\");\n$mail-\u003esetFrom(new MailAddress(\"my@server.com\", \"Server\"));\n$mail-\u003eaddToRecipient(new MailAddress(\"david@email.com\", \"David\"));\n\n// Let's get the instance of the service\n$mailService = Mouf::getSwiftMailService();\n\n// Finally, we send the mail\n$mailService-\u003esend($mail);\n```\n\nSending a mail with an attachment\n---------------------------------\n\n```php\nuse Mouf\\Utils\\Mailer\\Mail;\nuse Mouf\\Utils\\Mailer\\SwiftMailService;\n\n// The mail object\n$mail = new Mail();\n$mail-\u003esetTitle(\"My mail\");\n$mail-\u003esetBodyHtml(\"A nice image: \u003cimg src='cid:my@img.resource'/\u003e\");\n$mail-\u003esetFrom(new MailAddress(\"my@server.com\", \"Server\"));\n$mail-\u003eaddToRecipient(new MailAddress(\"david@email.com\", \"David\"));\n\n// The attachment\n$attachment = new MailAttachment();\n$attachment-\u003esetFileContent(file_get_contents('attachment.pdf'));\n$attachment-\u003esetMimeType('application/pdf');\n$mail-\u003eaddAttachement($attachment);\n\n// Let's get the instance of the service\n$mailService = Mouf::getSwiftMailService();\n\n// Finally, we send the mail\n$mailService-\u003esend($mail);\n```\n\nSending a mail with embedded image\n----------------------------------\n\n```php\nuse Mouf\\Utils\\Mailer\\Mail;\nuse Mouf\\Utils\\Mailer\\SwiftMailService;\n\n// The image we will embed:\n$embeddedImage = new MailAttachment();\n$embeddedImage-\u003esetFileContent(file_get_contents('img.png'));\n$embeddedImage-\u003esetMimeType('image/png');\n$embeddedImage-\u003esetAttachmentDisposition('inline');\n// Note: the format of the ID should be in the syntax of a mail: xxx@yyy.zzz\n$embeddedImage-\u003esetContentId('my@img.resource');\n\n// The mail object\n$mail = new Mail();\n$mail-\u003eaddAttachement($embeddedImage);\n$mail-\u003esetTitle(\"My mail\");\n$mail-\u003esetBodyHtml(\"A nice image: \u003cimg src='cid:my@img.resource'/\u003e\");\n$mail-\u003esetFrom(new MailAddress(\"my@server.com\", \"Server\"));\n$mail-\u003eaddToRecipient(new MailAddress(\"david@email.com\", \"David\"));\n\n// Let's get the instance of the service\n$mailService = Mouf::getSwiftMailService();\n\n// Finally, we send the mail\n$mailService-\u003esend($mail);\n```\n\nTo learn more about how to send mails, refer to the [Introduction to Mouf's mail architecture](http://mouf-php.com/packages/mouf/utils.mailer.mail-interface/README.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecodingmachine%2Futils.mailer.swift-mail-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthecodingmachine%2Futils.mailer.swift-mail-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecodingmachine%2Futils.mailer.swift-mail-service/lists"}