{"id":18743237,"url":"https://github.com/anthonybudd/wp_mail","last_synced_at":"2026-03-16T15:37:23.165Z","repository":{"id":41003611,"uuid":"89487944","full_name":"anthonybudd/WP_Mail","owner":"anthonybudd","description":"Send Templated emails with WordPress","archived":false,"fork":false,"pushed_at":"2022-08-28T09:14:11.000Z","size":146,"stargazers_count":92,"open_issues_count":4,"forks_count":26,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-04-09T18:18:17.396Z","etag":null,"topics":["email","smtp","wordpress"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anthonybudd.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-26T14:05:08.000Z","updated_at":"2025-03-30T07:39:49.000Z","dependencies_parsed_at":"2022-09-20T19:26:56.759Z","dependency_job_id":null,"html_url":"https://github.com/anthonybudd/WP_Mail","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonybudd%2FWP_Mail","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonybudd%2FWP_Mail/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonybudd%2FWP_Mail/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonybudd%2FWP_Mail/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anthonybudd","download_url":"https://codeload.github.com/anthonybudd/WP_Mail/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248085326,"owners_count":21045139,"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":["email","smtp","wordpress"],"created_at":"2024-11-07T16:10:44.690Z","updated_at":"2026-03-16T15:37:23.137Z","avatar_url":"https://github.com/anthonybudd.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WP_Mail - Send Dynamic Templated Emails with WordPress\n\nWP_Mail is the most popular, simplest and powerful dynamic email class available for WordPress. The class provides simple methods for attaching files, custom headers and lots of helper functions. The class only sends emails using the WordPress function wp_mail() , this means that all of your existing SMTP settings will continue to work with no additional config or set-up required.\n\n```php\n$email = WP_Mail::init()\n    -\u003eto('john.doe@gmail.com')\n    -\u003esubject('WP_Mail is great!')\n    -\u003etemplate(get_template_directory() .'/emails/demo.php', [\n        'name' =\u003e 'Anthony Budd',\n        'location' =\u003e 'London',\n        'skills' =\u003e [\n           'PHP',\n           'AWS',\n        ] \n    ])\n    -\u003esend();\n```\n\nemail.html\n```html\n\u003ch3\u003eYou have a new contact from enquirey!\u003c/h3\u003e\u003cbr\u003e\n\n\u003cp\u003e\n  \u003cstrong\u003eName:\u003c/strong\u003e\u003c?= $name ?\u003e\n\u003c/p\u003e\n\n\u003cp\u003e\n  \u003cstrong\u003eemail:\u003c/strong\u003e\n  \u003ca href=\"mailto:\u003c?= $email ?\u003e\"\u003e\u003c?= $email ?\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp\u003e\n  \u003cstrong\u003eSkills:\u003c/strong\u003e\u003cbr\u003e\n  \u003cul\u003e\n    \u003c?php foreach($skills as $skill): ?\u003e\n      \u003cli\u003e\n        \u003c?= $skill ?\u003e\n      \u003c/li\u003e\n    \u003c?php endforeach;?\u003e\n  \u003c/ul\u003e\n\u003c/p\u003e\n```\n\n***\n\n# Installation\n\nRequire WP_Mail with composer\n\n```\n$ composer require anthonybudd/WP_Mail\n```\n\n#### Or\n\nDownload the WP_Mail class and require it at the top of your functions.php file.\n\n```php\n    require 'src/WP_Mail.php';\n```\n\n***\n\n# Methods\n\n\n## to(), cc(), bcc()\nAll of these functions allow you to set an array or string of recipient(s) for your email as shown in the example below.\n\n```php\n    $email = WP_Mail::init()\n        -\u003eto([\n            'johndoe@gmail.com'\n            'mikesmith@gmail.com'\n        ])\n        -\u003ecc('JackTaylor@gmail.com')\n```\n\n\n## subject()\nTo set the subject field use the subject function. The first argument will be the emails subject.\n\n```php\n    $email = WP_Mail::init()\n        -\u003esubject('This this the subject')\n```\n\n## from()\nTo set the from header there is a useful helper function.\n\n```php\n    $email = WP_Mail::init()\n        -\u003efrom('John Doe \u003cjohn.doe@ideea.co.uk\u003e')\n```\n\n\n## attach()\nSimilar to the to, cc and bcc, methods the attach method can accept a string or array of stings. This strings must be absolute file paths, this method will throw if the file does not exist.\n\n```php\n    $email = WP_Mail::init()\n        -\u003eattach(ABSPATH .'wp-content/uploads/2017/06/file.pdf')\n```\n\n\n## template($templatePath, $variables = [])\nThe templet method is for setting the path to the html email template. The second argument is for an asoc array where the keys will correspond to your HTML email’s variables. Variables are optional and are not required for templates that do not have any variables.\n\n```php\n    $email = WP_Mail::init()\n        -\u003etemplate(get_template_directory() .'/email.html', [\n           'name' =\u003e 'Anthony Budd',\n           'job'  =\u003e 'Developer',\n        ])\n```\n\n\n### templateHeader($templatePath, $variables = [])\n### templateFooter($templatePath, $variables = [])\nSelf-explanatory  \n\n\nIf you are sending many emails the beforeTemplate() and afterTemplate() will allow you to append and prepen templated HTML to your emails.\n```php\n    $email = (new WP_Mail)\n        -\u003ebeforeTemplate(get_template_directory() .'/email-header.html')\n\t\t-\u003eafterTemplate(get_template_directory() .'/email-footer.html')\n        -\u003etemplate(get_template_directory() .'/email.html', [\n           'name' =\u003e 'Anthony Budd',\n           'job'  =\u003e 'Developer',\n        ])\n```\n\n\n\n\n## headers()\nThis method allows you to set additional headers for your email. This can be an array of headers or a single string header.\n\n```php\n    $email = WP_Mail::init()\n        -\u003eheaders(\"From: John Doe \u003cjohn.doe@ideea.co.uk\u003e\")\n```\n\n```php\n    $email = WP_Mail::init()\n        -\u003eheaders([\n            \"From: John Doe \u003cjohn.doe@ideea.co.uk\u003e\",\n            \"X-Mailer: PHP/\". phpversion(),\n            \"Reply-To: webmaster@ideea.co.uk\",\n            \"Content-type: text/html; charset=iso-8859-1\",\n        ])\n```\n\n\n## render()\nThis method is called by the send() method, the result is given directly to the $message argument of the wp_mail function. This can be used for testing or for displaying what an email will look like for admins.\n\nThe render() method is called when you send an email will use a simple bit of regex to find and replace variables using a mustache-esque syntax. Finally the method sends the email using WordPresses built in wp_mail() function.\n\n```php\n    $email = (new WP_Mail)\n        -\u003esend()\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanthonybudd%2Fwp_mail","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanthonybudd%2Fwp_mail","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanthonybudd%2Fwp_mail/lists"}