Exemple #1
0
<?php

include "SimpleMailer.class.php";
include "../SimpleTpl/SimpleTpl.class.php";
#include("Smarty.class.php");
$mail = new SimpleMailer();
if (!$mail->from("*****@*****.**", "LeanDNS Security Log")) {
    die("Invalid E-Mail");
}
$mail->replyto("*****@*****.**", "Support Department");
$mail->to("*****@*****.**", "Mikkel Mikjaer Christensen");
$mail->to("*****@*****.**", "Mikkel Mikjaer Christensen");
$mail->subject("Test email from SimpleMailer");
$mail->template_plain("demo_plain.tpl");
$mail->template_html("demo_html.tpl");
$mail->assign("value", "This is my testvalue");
$mail->send();
 public function testMakeAddressText()
 {
     $makeAddressText = getMethod('SimpleMailer', 'makeAddressText');
     $Encoding = getProperty('SimpleMailer', 'Encoding');
     $mailer = new SimpleMailer();
     $mailer->setFromEncoding("EUC-JP");
     $mailer->setCharSet("UTF-8");
     $value = $makeAddressText->invokeArgs($mailer, array('*****@*****.**', ''));
     $this->assertEquals('*****@*****.**', $value);
     $value = $makeAddressText->invokeArgs($mailer, array('*****@*****.**', 'test'));
     $this->assertEquals('test <*****@*****.**>', $value);
 }
<?php

session_start();
header("Content-type:text/html;charset=utf8");
if ($_GET) {
    $to = $_GET['email'];
    include "./lib/SimpleMailer.php";
    $config = (include './config/email.php');
    $smailer = new SimpleMailer($config['host'], $config['port'], $config['user'], $config['pass']);
    if ($smailer) {
        $subject = "PHP study 注册验证码";
        $_SESSION['verifycode']['code'] = mt_rand(0, pow(10, 6) - 1);
        $content = "请使用验证码:{$_SESSION['verifycode']['code']}在十分钟之内完成注册";
        if ($smailer->send_email($config['from'], $to, $subject, $content)) {
            $_SESSION['verifycode']['time'] = time();
            echo 200;
            //邮件发送成功
        } else {
            unset($_SESSION['verifycode']);
            $smailer->show_debug();
            echo 111;
            //邮件发送失败
        }
    } else {
        echo 222;
        //初始化错误
    }
} else {
    echo 333;
    //没有提交邮箱
}