Source for file xoopsmailer.php
Documentation is available at xoopsmailer.php
// $Id: xoopsmailer.php 797 2006-11-08 02:21:38Z skalpa $
// ------------------------------------------------------------------------ //
// XOOPS - PHP Content Management System //
// Copyright (c) 2000 XOOPS.org //
// <http://www.xoops.org/> //
// ------------------------------------------------------------------------ //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// You may not change or alter any portion of this comment or credits //
// of supporting developers from this source code or any supporting //
// source code which is considered copyrighted (c) material of the //
// original comment or credit authors. //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// You should have received a copy of the GNU General Public License //
// along with this program; if not, write to the Free Software //
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
// ------------------------------------------------------------------------ //
// Author: Kazumi Ono (AKA onokazu) //
// URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
// Project: The XOOPS Project //
// ------------------------------------------------------------------------- //
die("XOOPS root path not defined");
if (isset ($GLOBALS['xoopsConfig']['language']) && file_exists(XOOPS_ROOT_PATH. '/language/'. $GLOBALS['xoopsConfig']['language']. '/mail.php')) {
include_once XOOPS_ROOT_PATH. '/language/'. $GLOBALS['xoopsConfig']['language']. '/mail.php';
include_once XOOPS_ROOT_PATH. '/language/english/mail.php';
* The new Multimailer class that will carry out the actual sending and will later replace this class.
* If you're writing new code, please use that class instead.
include_once(XOOPS_ROOT_PATH. "/class/mail/xoopsmultimailer.php");
* Class for sending mail.
* Changed to use the facilities of {@link XoopsMultiMailer}
* @deprecated use {@link XoopsMultiMailer} instead.
* @author Kazumi Ono <onokazu@xoops.org>
* @copyright (c) 2000-2003 The Xoops Project - www.xoops.org
* reference to a {@link XoopsMultiMailer}
* @since 21.02.2003 14:14:13
// array of user class objects
// array of email addresses
// reset all properties to default
// Change below to \r\n if you have problem sending mail
if ( substr($value, - 1, 1) != "/" ) {
$this->priority = trim($value);
function send($debug = false)
if ( !($fd = @fopen($path, 'r')) ) {
if (!empty($this->priority)) {
$this->headers[] = "X-Priority: " . $this->priority;
//$this->headers[] = "X-Mailer: PHP/".phpversion();
//$this->headers[] = "Return-Path: ".$this->fromEmail;
// TODO: we should have an option of no-reply for private messages and emails
// to which we do not accept replies. e.g. the site admin doesn't want a
// a lot of message from people trying to unsubscribe. Just make sure to
// give good instructions in the message.
// add some standard tags (user-dependent tags are included later)
$this->assign ('X_ADMINMAIL', $xoopsConfig['adminmail']);
$this->assign ('X_SITENAME', $xoopsConfig['sitename']);
// TODO: also X_ADMINNAME??
// TODO: X_SIGNATURE, X_DISCLAIMER ?? - these are probably best
// done as includes if mail templates ever get this sophisticated
// replace tags with actual values
// send mail to specified mail addresses, if any
foreach ( $this->toEmails as $mailaddr ) {
// send message to specified users, if any
// NOTE: we don't send to LIST of recipients, because the tags
// below are dependent on the user identity; i.e. each user
// receives (potentially) a different message
foreach ( $this->toUsers as $user ) {
// set some user specific variables
$text = str_replace("{X_UEMAIL}", $user->getVar("email"), $text );
$text = str_replace("{X_UNAME}", $user->getVar("uname"), $text );
$text = str_replace("{X_UACTLINK}", XOOPS_URL. "/user.php?op=actv&id=". $user->getVar("uid"). "&actkey=". $user->getVar('actkey'), $text );
if ( !$this->sendMail($user->getVar("email"), $subject, $text, $headers) ) {
if ( !$this->sendPM($user->getVar("uid"), $subject, $text) ) {
function sendPM($uid, $subject, $body)
$pm = & $pm_handler->create();
$pm->setVar("subject", $subject);
$pm->setVar('from_userid', !empty($this->fromUser) ? $this->fromUser->getVar('uid') : $xoopsUser->getVar('uid'));
$pm->setVar("msg_text", $body);
$pm->setVar("to_userid", $uid);
if (!$pm_handler->insert($pm)) {
* Uses the new XoopsMultiMailer
* @return boolean FALSE on error.
function sendMail($email, $subject, $body, $headers)
$this->multimailer->ClearAllRecipients();
$this->multimailer->AddAddress($email);
$this->multimailer->Subject = $subject;
$this->multimailer->Body = $body;
$this->multimailer->CharSet = $this->charSet;
$this->multimailer->Encoding = $this->encoding;
$this->multimailer->Sender = $this->multimailer->From = $this->fromEmail;
$this->multimailer->ClearCustomHeaders();
foreach ($this->headers as $header) {
$this->multimailer->AddCustomHeader($header);
if (!$this->multimailer->Send()) {
$this->errors[] = $this->multimailer->ErrorInfo;
if ( !empty($this->errors) ) {
foreach ( $this->errors as $error ) {
foreach ( $this->success as $suc ) {
function assign($tag, $value= null)
foreach ( $tag as $k => $v ) {
if ( !empty($tag) && isset ($value) ) {
// TEMPORARY FIXME: until the X_tags are all in here
// if ( substr($tag, 0, 2) != "X_" ) {
if (preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i",$email) ) {
foreach ( $email as $e) {
$this->setToUsers($member_handler->getUsersByGroup($group->getVar('groupid'), true));
// to be overidden by lang specific mail class, if needed
// to be overidden by lang specific mail class, if needed
// to be overidden by lang specific mail class, if needed
|