SendMail

Summary: Easily add PHPMailer to send SMTP email from your PHP code
Version: 2020.12.8
Prerequisites: SSH access to server with permission to install PHPMailer
Status: Active
Maintainer: Kirk Siqveland Kirk
License: (Apache 2.0|BSD-3-clause|BSD-2-clause|GPL|LGPL|MIT|MPL-2.0|CDDL-1.0|EPL-1.0) - OpenSourceLicenses Cookbook:Cookbook Licenses
Categories: Uncategorized
Users: (view? / edit)
Discussion: SendMail-Talk?

Questions answered by this recipe

  • Can I add SMTP email using my own email account from within my wiki?
  • Can I use SMTP email within other pmwiki functions / code?
  • Can I use PHP/JS to send email from within other (custom) functions automatically?

All sections are optional, you can remove those that do not apply to your recipe, and add new ones.

Description

Instructions and a simple recipe to handle SMTP email using PHPMailer

This was something I worked up for a couple of different projects, particularly the MyDBLogin-PMW project where I need to use email verification.
I recently wanted to add notification of certain events to my code, so I turned the code into a recipe to make it is easy to drop into any PMWiki installation.

Installation


You will need to add PHPMailer to your server.
Instructions may vary for your host, but here's what I had to do:

  • Log into your server via SSH.
  • Navigate to the user home directory
[server]$ CD ~
  • Download PHPMailer form GitHub.com
[server]$ wget https://github.com/PHPMailer/PHPMailer/archive/master.zip
  • Unzip the file
[server]$ unzip master.zip
  • Rename the file from PHPMailer-master to PHPMailer
[server]$ mv PHPMailer-master PHPMailer

--- --- ---

Download this file SendMail.zipΔ
Unzip the file and edit the SendMail.php file to set the constants to match your server and email requirements.
The file is well commented to help you figure those out.

Copy the edited SendMail.php to your pmwiki/cookbook/ directory

Now, add This to your /local/config.php file:

##-- SEND MAIL PHPMailer recipe--
include_once ('cookbook/SendMail.php');

(be sure you save the config.php file to your server again.)

And...

You can now use the function:

send_mail($email,$message,$subject)

from other php functions inside of PMWiki

Configuration

You must have PHPMailer installed on your server & Set the SendMail.php file to match your server configuration.

There are commented out parts if you want to add more details to the email messages you send.
As is, this just uses your SendMail.php for the send FROM information, so you just pass the send TO information to the function.

If you want to modify the code a little you can use PHPMailer to handle POP3 instead of SMTP.

Usage

from any PHP module in use in your PMWiki installation you can add a line like:

send_mail($mailto,$messagebody, $subjectline)

Notes

To do / some day / maybe

 Add a Markup to allow sending of email from a wiki page - this has serious security issues so I have left it off for now.

If you have future plans or wishes for this recipe.

Change log / Release notes

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".

See also

Cookbook /
SMTPMail  Send automated e-mails via your SMTP server (Experimental)

Contributors

Comments

See discussion at SendMail-Talk?

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.