noalyss  Version-6.7.2
Public Member Functions | Private Attributes
Sendmail Class Reference

Description of class_sendmail. More...

Public Member Functions

 add_file (FileToSend $file)
 Add file to the message.
 compose ()
 create the message before sending
 mailto ($p_mailto)
 set the recipient
 send ()
 Send the message.
 set_from ($p_from)
 set the from $p_from has the form name <info@phpcompta.eu>
 set_message ($p_message)
 body of the message (utf8)
 set_subject ($p_subject)
 verify ()
 verify that the message is ready to go

Private Attributes

 $afile
 $content
 $from
 $mailto
 $message
 $subject

Detailed Description

Description of class_sendmail.

Author:
dany

Definition at line 29 of file class_sendmail.php.


Member Function Documentation

Add file to the message.

Parameters:
FileToSend$filefile to add to the message

Definition at line 79 of file class_sendmail.php.

References $file.

    {
        $this->afile[] = $file;
    }

create the message before sending

Definition at line 103 of file class_sendmail.php.

References $content, $file, $uid, content, from, and verify().

    {
        $this->verify();
        $uid = md5(uniqid(time()));

        // a random hash will be necessary to send mixed content
        $separator = md5(time());

        // carriage return type (we use a PHP end of line constant)
        $eol = PHP_EOL;

        // main header (multipart mandatory)
        $headers = "From: " . $this->from . $eol;
        $headers .= "MIME-Version: 1.0" . $eol;
        $headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol . $eol;
        $headers .= "Content-Transfer-Encoding: 7bit" . $eol;
        $headers .= "This is a MIME encoded message." . $eol . $eol;
        $headers .= $eol . $eol;

        // message
        $headers .= "--" . $separator . $eol;
        $headers .= "Content-Type: text/plain; charset=\"utf-8\"" . $eol;
        $headers .= "Content-Transfer-Encoding: 7bit" . $eol . $eol;
        $headers .= $this->message . $eol . $eol;

        // attachment
        for ($i = 0; $i < count($this->afile); $i++)
        {
            $file = $this->afile[$i];
            $file_size = filesize($file->full_name);
            $handle = fopen($file->full_name, "r");
            $content = fread($handle, $file_size);
            fclose($handle);
            $content = chunk_split(base64_encode($content));
            $headers .= "--" . $separator . $eol;
            $headers .= "Content-Type: " . $file->type . "; name=\"" . $file->filename . "\"" . $eol;
            $headers .= "Content-Disposition: attachment; filename=\"" . $file->filename . "\"" . $eol;
            $headers .= "Content-Transfer-Encoding: base64" . $eol;
            $headers.=$eol;
            $headers .= $content . $eol . $eol;
        }
        $headers .= "--" . $separator . "--";
        $this->content = $headers;
    }
Sendmail::mailto ( p_mailto)

set the recipient

Parameters:
type$p_mailtohas the form name <email@email.com>

Definition at line 61 of file class_sendmail.php.

Referenced by send().

    {
        $this->mailto = $p_mailto;
    }

Send the message.

Exceptions:
Exception

Definition at line 151 of file class_sendmail.php.

References content, and mailto().

    {
        //SEND Mail
        if (!mail($this->mailto, $this->subject, "", $this->content))
        {
            throw new Exception('send failed');
        }
    }
Sendmail::set_from ( p_from)

set the from $p_from has the form name <info@phpcompta.eu>

Definition at line 43 of file class_sendmail.php.

References from.

    {
        $this->from = $p_from;
    }
Sendmail::set_message ( p_message)

body of the message (utf8)

Parameters:
type$p_message

Definition at line 70 of file class_sendmail.php.

    {
        $this->message = $p_message;
    }
Sendmail::set_subject ( p_subject)
Parameters:
$p_subjectset the subject

Definition at line 52 of file class_sendmail.php.

    {
        $this->subject = $p_subject;
    }

verify that the message is ready to go

Exceptions:
Exception

Definition at line 88 of file class_sendmail.php.

References $array, $name, and trim().

Referenced by compose().

    {
        $array = explode(",", "from,subject,mailto,message");
        for ($i = 0; $i < count($array); $i++)
        {
            $name = $array[$i];
            if (trim($this->$name) == "")
            {
                throw new Exception($name ._(" est vide"));
            }
        }
    }

Field Documentation

Sendmail::$afile [private]

Definition at line 33 of file class_sendmail.php.

Sendmail::$content [private]

Definition at line 37 of file class_sendmail.php.

Referenced by compose().

Sendmail::$from [private]

Definition at line 36 of file class_sendmail.php.

Sendmail::$mailto [private]

Definition at line 32 of file class_sendmail.php.

Sendmail::$message [private]

Definition at line 35 of file class_sendmail.php.

Sendmail::$subject [private]

Definition at line 34 of file class_sendmail.php.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations