SendMail
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?
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:
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.
Change log / Release notes
See also
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.