TripletaiL Japanese Web Application Framework

メールの送信 - チュートリアル

メールを送信してみましょう。

main.cgi

#!/usr/local/bin/perl

use strict;
use warnings;
use Tripletail qw(tl.ini);

$TL->startCgi(
    -main => \&main,
);

sub main
{
    my $from = '';
    my $to = '';
    my $subject = '';
    my $text = '';

    my $mail = $TL->newMail->setHeader(
        From => $from,
        To => $to,
        Subject => $subject,
    )->setBody($text)->toStr;

    my $sendmail = $TL->newSendmail->connect
    ->send(
        -from => $from,
        -rcpt => $to,
        -data => $mail,
    )->disconnect;

    my $t = $TL->newTemplate('template.html', 'utf8');
    $t->expand(
        FROM => $from,
        TO => $to,
        SUBJECT => $subject,
        TEXT => $text,
    );
    $t->flush;
}

tl.ini

[TL]

[Sendmail]
method = smtp

template.html

<!DOCTYPE html>
<HTML>
  <BODY>
    <&FROM>
    <br>
    <&TO>
    <br>
    <&SUBJECT>
    <br>
    <&TEXT>
    <br>
    へ送信しました。
  </BODY>
</HTML>

一覧へ戻る