# phpman > perldoc > Mail::Mailer

## NAME
    [Mail::Mailer](https://www.chedong.com/phpMan.php/perldoc/Mail%3A%3AMailer/markdown) - send simple emails

## INHERITANCE
     [Mail::Mailer](https://www.chedong.com/phpMan.php/perldoc/Mail%3A%3AMailer/markdown)
       is an [IO::Handle](https://www.chedong.com/phpMan.php/perldoc/IO%3A%3AHandle/markdown)

## SYNOPSIS
      use [Mail::Mailer](https://www.chedong.com/phpMan.php/perldoc/Mail%3A%3AMailer/markdown);
      use [Mail::Mailer](https://www.chedong.com/phpMan.php/perldoc/Mail%3A%3AMailer/markdown) qw(mail);    # specifies default mailer

      $mailer = [Mail::Mailer](https://www.chedong.com/phpMan.php/perldoc/Mail%3A%3AMailer/markdown)->new;
      $mailer = [Mail::Mailer](https://www.chedong.com/phpMan.php/perldoc/Mail%3A%3AMailer/markdown)->new($type, @args);

      $mailer->open(\%headers);
      print $mailer $body;
      $mailer->close
          or die "couldn't send whole message: $!\n";

## DESCRIPTION
    Sends mail using any of the built-in methods. As TYPE argument to new(), you can specify any of

    "sendmail"
        Use the "sendmail" program to deliver the mail.

    "smtp"
        Use the "smtp" protocol via [Net::SMTP](https://www.chedong.com/phpMan.php/perldoc/Net%3A%3ASMTP/markdown) to deliver the mail. The server to use can be
        specified in @args with

         $mailer = [Mail::Mailer](https://www.chedong.com/phpMan.php/perldoc/Mail%3A%3AMailer/markdown)->new('smtp', Server => $server);

        The smtp mailer does not handle "Cc" and "Bcc" lines, neither their "Resent-*" fellows. The
        "Debug" options enables debugging output from "[Net::SMTP](https://www.chedong.com/phpMan.php/perldoc/Net%3A%3ASMTP/markdown)".

        [added 2.21] You may also use the "StartTLS => 1" options to upgrade the connection with
        STARTTLS. You need "libnet" version 1.28 (2014) for this to work.

        You may also use the "Auth => [ $user, $password ]" option for SASL authentication. To make
        this work, you have to install the [Authen::SASL](https://www.chedong.com/phpMan.php/perldoc/Authen%3A%3ASASL/markdown) distribution yourself: it is not
        automatically installed.

    "smtps"
        This option is deprecated when you have "libnet" 1.28 (2014) and above.

        Use the smtp over ssl protocol via [Net::SMTP::SSL](https://www.chedong.com/phpMan.php/perldoc/Net%3A%3ASMTP%3A%3ASSL/markdown) to deliver the mail. Usage is identical to
        "smtp". You have to install [Authen::SASL](https://www.chedong.com/phpMan.php/perldoc/Authen%3A%3ASASL/markdown) as well.

         $mailer = [Mail::Mailer](https://www.chedong.com/phpMan.php/perldoc/Mail%3A%3AMailer/markdown)->new('smtps', Server => $server);

    "qmail"
        Use qmail's qmail-inject program to deliver the mail.

    "testfile"
        Used for debugging, this displays the data to the file named in
        $[Mail::Mailer::testfile::config](https://www.chedong.com/phpMan.php/perldoc/Mail%3A%3AMailer%3A%3Atestfile%3A%3Aconfig/markdown){outfile} which defaults to a file named "mailer.testfile".
        No mail is ever sent.

    "[Mail::Mailer](https://www.chedong.com/phpMan.php/perldoc/Mail%3A%3AMailer/markdown)" will search for executables in the above order. The default mailer will be the
    first one found.

## METHODS
### Constructors
    [Mail::Mailer](https://www.chedong.com/phpMan.php/perldoc/Mail%3A%3AMailer/markdown)->new($type, %options)
        The $type is one of the back-end sender implementations, as described in the DESCRIPTION
        chapter of this manual page. The %options are passed to that back-end.

    $obj->open(HASH)
        The HASH consists of key and value pairs, the key being the name of the header field (eg,
        "To"), and the value being the corresponding contents of the header field. The value can
        either be a scalar (eg, "<gnat@frii.com>") or a reference to an array of scalars ("eg,
        ['<gnat@frii.com>', '<Tim.Bunce@ig.co.uk>']").

## DETAILS
  ENVIRONMENT VARIABLES
    PERL_MAILERS
        Augments/override the build in choice for binary used to send out our mail messages.

        Format:

            "type1:mailbinary1;mailbinary2;...:type2:mailbinaryX;...:..."

        Example: assume you want you use private sendmail binary instead of mailx, one could set
        "PERL_MAILERS" to:

            "mail:/does/not/exists:sendmail:$HOME/test/bin/sendmail"

        On systems which may include ":" in file names, use "|" as separator between type-groups.

            "mail:c:/does/not/exists|sendmail:$HOME/test/bin/sendmail"

  BUGS
    [Mail::Mailer](https://www.chedong.com/phpMan.php/perldoc/Mail%3A%3AMailer/markdown) does not help with folding, and does not protect against various web-script hacker
    attacks, for instance where a new-line is inserted in the content of the field.

## SEE ALSO
    This module is part of the MailTools distribution, <http://perl.overmeer.net/mailtools/>.

## AUTHORS
    The MailTools bundle was developed by Graham Barr. Later, Mark Overmeer took over maintenance
    without commitment to further development.

    [Mail::Cap](https://www.chedong.com/phpMan.php/perldoc/Mail%3A%3ACap/markdown) by Gisle Aas <<aas@oslonett.no>>. [Mail::Field::AddrList](https://www.chedong.com/phpMan.php/perldoc/Mail%3A%3AField%3A%3AAddrList/markdown) by Peter Orbaek <<poe@cit.dk>>.
    [Mail::Mailer](https://www.chedong.com/phpMan.php/perldoc/Mail%3A%3AMailer/markdown) and [Mail::Send](https://www.chedong.com/phpMan.php/perldoc/Mail%3A%3ASend/markdown) by Tim Bunce <<Tim.Bunce@ig.co.uk>>. For other contributors see
    ChangeLog.

## LICENSE
    Copyrights 1995-2000 Graham Barr <<gbarr@pobox.com>> and 2001-2017 Mark Overmeer
    <<perl@overmeer.net>>.

    This program is free software; you can redistribute it and/or modify it under the same terms as
    Perl itself. See <http://www.perl.com/perl/misc/Artistic.html>

