Skip to content
Snippets Groups Projects
emailtest.php 5.37 KiB
Newer Older
  • Learn to ignore specific revisions
  • Jared Hancock's avatar
    Jared Hancock committed
    <?php
    /*********************************************************************
        emailtest.php
    
    
        Email Diagnostic
    
    Jared Hancock's avatar
    Jared Hancock committed
    
        Peter Rotich <peter@osticket.com>
    
        Copyright (c)  2006-2013 osTicket
    
    Jared Hancock's avatar
    Jared Hancock committed
        http://www.osticket.com
    
        Released under the GNU General Public License WITHOUT ANY WARRANTY.
        See LICENSE.TXT for details.
    
        vim: expandtab sw=4 ts=4 sts=4:
    **********************************************************************/
    require('admin.inc.php');
    include_once(INCLUDE_DIR.'class.email.php');
    
    include_once(INCLUDE_DIR.'class.csrf.php');
    
    Jared Hancock's avatar
    Jared Hancock committed
    $info=array();
    $info['subj']='osTicket test email';
    
    if($_POST){
        $errors=array();
        $email=null;
        if(!$_POST['email_id'] || !($email=Email::lookup($_POST['email_id'])))
    
            $errors['email_id']=__('Select from email address');
    
    Jared Hancock's avatar
    Jared Hancock committed
    
        if(!$_POST['email'] || !Validator::is_email($_POST['email']))
    
            $errors['email']=__('To email address required');
    
    Jared Hancock's avatar
    Jared Hancock committed
    
        if(!$_POST['subj'])
    
            $errors['subj']=__('Subject required');
    
    Jared Hancock's avatar
    Jared Hancock committed
    
        if(!$_POST['message'])
    
            $errors['message']=__('Message required');
    
    Jared Hancock's avatar
    Jared Hancock committed
    
        if(!$errors && $email){
    
            if($email->send($_POST['email'],$_POST['subj'],
    
                    Format::sanitize($_POST['message']),
                    null, array('reply-tag'=>false))) {
    
                $msg=Format::htmlchars(sprintf(__('Test email sent successfully to <%s>'),
                    $_POST['email']));
    
                Draft::deleteForNamespace('email.diag');
            }
    
    Jared Hancock's avatar
    Jared Hancock committed
            else
    
                $errors['err']=__('Error sending email - try again.');
    
    Jared Hancock's avatar
    Jared Hancock committed
        }elseif($errors['err']){
    
            $errors['err']=__('Error sending email - try again.');
    
    Jared Hancock's avatar
    Jared Hancock committed
        }
    }
    $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
    $nav->setTabActive('emails');
    
    $ost->addExtraHeader('<meta name="tip-namespace" content="emails.diagnostic" />',
        "$('#content').data('tipNamespace', '".$tip_namespace."');");
    
    Jared Hancock's avatar
    Jared Hancock committed
    require(STAFFINC_DIR.'header.inc.php');
    ?>
    
    <form action="emailtest.php" method="post" id="save">
    
     <?php csrf_token(); ?>
    
    Jared Hancock's avatar
    Jared Hancock committed
     <input type="hidden" name="do" value="<?php echo $action; ?>">
    
     <h2><?php echo __('Test Outgoing Email');?></h2>
    
    Jared Hancock's avatar
    Jared Hancock committed
     <table class="form_table" width="940" border="0" cellspacing="0" cellpadding="2">
        <thead>
            <tr>
                <th colspan="2">
    
                    <em><?php echo __('Use the following form to test whether your <strong>Outgoing Email</strong> settings are properly established.');
                        ?>&nbsp;<i class="help-tip icon-question-sign" href="#test_outgoing_email"></i></em>
    
    Jared Hancock's avatar
    Jared Hancock committed
                </th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td width="120" class="required">
    
                    <?php echo __('From');?>:
    
    Jared Hancock's avatar
    Jared Hancock committed
                </td>
                <td>
                    <select name="email_id">
    
                        <option value="0">&mdash; <?php echo __('Select FROM Email');?> &mdash;</option>
    
    Jared Hancock's avatar
    Jared Hancock committed
                        <?php
                        $sql='SELECT email_id,email,name,smtp_active FROM '.EMAIL_TABLE.' email ORDER by name';
                        if(($res=db_query($sql)) && db_num_rows($res)){
                            while(list($id,$email,$name,$smtp)=db_fetch_row($res)){
                                $selected=($info['email_id'] && $id==$info['email_id'])?'selected="selected"':'';
                                if($name)
                                    $email=Format::htmlchars("$name <$email>");
                                if($smtp)
    
                                    $email.=' ('.__('SMTP').')';
    
    Jared Hancock's avatar
    Jared Hancock committed
    
                                echo sprintf('<option value="%d" %s>%s</option>',$id,$selected,$email);
                            }
                        }
                        ?>
                    </select>
                    &nbsp;<span class="error">*&nbsp;<?php echo $errors['email_id']; ?></span>
                </td>
            </tr>
            <tr>
                <td width="120" class="required">
    
                    <?php echo __('To');?>:
    
    Jared Hancock's avatar
    Jared Hancock committed
                </td>
                <td>
                    <input type="text" size="60" name="email" value="<?php echo $info['email']; ?>">
                    &nbsp;<span class="error">*&nbsp;<?php echo $errors['email']; ?></span>
                </td>
            </tr>
            <tr>
                <td width="120" class="required">
    
                    <?php echo __('Subject');?>:
    
    Jared Hancock's avatar
    Jared Hancock committed
                </td>
                <td>
                    <input type="text" size="60" name="subj" value="<?php echo $info['subj']; ?>">
                    &nbsp;<span class="error">*&nbsp;<?php echo $errors['subj']; ?></span>
                </td>
            </tr>
            <tr>
                <td colspan=2>
    
                    <div style="padding-top:0.5em;padding-bottom:0.5em">
    
                    <em><strong><?php echo __('Message');?></strong>: <?php echo __('email message to send.');?></em>&nbsp;<span class="error">*&nbsp;<?php echo $errors['message']; ?></span></div>
    
                    <textarea class="richtext draft draft-delete" name="message" cols="21"
    
                        rows="10" style="width: 90%;" <?php
        list($draft, $attrs) = Draft::getDraftAndDataAttrs('email.diag', false, $info['message']);
        echo $attrs; ?>><?php echo $draft ?: $info['message'];
                     ?></textarea>
    
    Jared Hancock's avatar
    Jared Hancock committed
                </td>
            </tr>
        </tbody>
    </table>
    <p style="padding-left:225px;">
    
        <input type="submit" name="submit" value="<?php echo __('Send Message');?>">
        <input type="reset"  name="reset"  value="<?php echo __('Reset');?>">
        <input type="button" name="cancel" value="<?php echo __('Cancel');?>" onclick='window.location.href="emails.php"'>
    
    Jared Hancock's avatar
    Jared Hancock committed
    </p>
    </form>
    <?php
    include(STAFFINC_DIR.'footer.inc.php');
    ?>