[Précédent (date)] [Suivant (date)] [Précédent (sujet)] [Suivant (sujet)] [Index par date] [Index par sujet]

Re: Sendmail



Bonjour Jean-François,

C'est probablement parce que tu utilises la fonction mail() de
PHP.

Utilise plutôt la classe que je t'ai attaché. Dans ton code, inscris

Include "smtp.php";  // Defines smtp classes...

$mailserver="localhost";
$from="[email protected]";
$recipient="[email protected]";
$sujet="Bonjour...";
$message="Bonjour...";

$smail = new SMTP($mailserver); //Initiate class into object.
if ($smail->errno)
    die ($smail->errmsg());

if (!$smail->SetFrom($from))
    die ($smail->errmsg());

if (!$smail->SetToTitle($sujet))
    die ($smail->errmsg());

if (!$smail->SetText($message))
    die ($smail->errmsg());

// mail en simple 'text' ou 'html'
if (!$smail->sendmail("html"))
    die ($smail->errmsg());

if (!$smail->end())
    die ($smail->errmsg());

Salutations!

__________________________________________________
Real Melancon
Network/Unix Admin.
Internet Expresso


> J'ai installer un serveur web avec apache, php, mysql et sendmail.
>
> lors de mes fonction mail quand on recoit le e-mail, il est marquer
> nobody  dans la place de la personne qui send le mail. comment je peux
> changer sa ,  cest dans la config de senmail ou de php.
>
> Jean-François Dufour
> Programmeur
> Technicien réseaux, serveur
> Tel. : 450-477-1465
> Pax : 450-477-3659
> http://www.prestigecollision.com
> -----------------------------------------------
> Service internet sécurisé
> http://www.monitech.ca
> -----------------------------------------------
>
> --
> Liste de diffusion aide
> http://linux-quebec.org/mailman/listinfo/aide


<?php

Class SMTP {

// global varibles

Var     $errno     = 0;
Var     $errmsg    = '';
Var     $errors=Array(
        1 => 'Invalid Input',
        2 => 'Unable to establish connection',
        3 => 'Connection timed out',
        4 => 'SMTP Error returned',
        );

Var     $server         = "";
Var     $user           = "";
Var     $sock           = false;
Var     $readlength     = 1024;

Var     $mailto         = array();
Var     $mailcc         = array();
Var     $mailfrom       = "";
Var     $mailfromtitle  = '';
Var     $mailsubject    = "";
Var     $mailtext       = "";
Var     $attachments    = array();

Var     $deadmsg        = "";
Var     $verbose        = "0";
                                //Modify this for verbose output of the transaction..
                                //1 for verbose
                                //0 for silent

Function SMTP($server, $timeout=10)
        {
        // Return false if we can't get an SMTP connection...

        if (strlen($server)<=0)
                return $this->error(1, 'server');
        else    $this->server=$server;

        if (!$this->sock = fsockopen($server, 25, &$errno, &$errstr, $timeout))
                return $this->error(2);

        if (!socket_set_blocking($this->sock, true))
                return $this->error(4, 'set blocking');

        if (!$this->GetFeedback())
                return $this->error(2, 'during onset');

        return true;
        }

Function Error($errno, $message)
        {
        $this->errno=$errno;
        $this->errmsg.=$message;
        return false;
        }

Function ErrMsg($error=false)
        {
        if (false===$error)
                {
                $errno=$this->errno;
                return $this->$errors[$errno].' '.$this->errmsg;
                }
        else    return $this->$errors[$error];
        }

Function ErrNo()
        {
        return $this->errno;
        }

Function SetSubject($subject)
        {
        if (strlen($subject)<=0)
                return $this->Error(1, 'subject');
        $this->mailsubject = ereg_replace("\n"," ",$subject);
        return true;
        }

Function setText($text)
        {
        if (strlen($text)<=0)
                return $this->Error(1, 'message body');
        $text = ereg_replace("\n.\n", "\n. \n", $text);
        $text = ereg_replace("\n.\r", "\n. \r", $text);
        $this->mailtext = $text;
        return true;
        }

Function SetTo($to)
        {
        // THIS CAN BE USED TO SET AS MANY "BCC" RECIPIENTS AS YOU LIKE.
        if (strlen($to)<=0)
                return $this->Error(1, '"to" too short');
        if (strlen($to)>=129)
                return $this->Error(1, '"to" too long');
        $this->mailto[]=$to;
        return true;
        }

Function SetToTitle($title)
        {
        if (strlen($title)<=0)
                return $this->Error(1, 'totitle too short');
        if (strlen($title)>=128)
                return $this->Error(1, 'totitle too long');
        $this->mailtotitle="<$title>";
        return true;
        }

function SetCC($to)
        {
        // THIS WORKS LIKE "SETTO" ABOVE, BUT TELLS EVERYBODY WHO'S INVOLVED.
        // This is a potential privacy issue...

        if (!$this->setto($to))
                return false;
        $this->mailcc[]=$to;
        return true;
        }

Function SetFrom($from)
        {
        if (strlen($from)<=0)
                return $this->Error(1, 'from too short');
        if (strlen($from)>=128)
                return $this->Error(1, 'from too long');
        $this->mailfrom=$from;
        return true;
        }

Function SetFromTitle($title)
        {
        if (strlen($title)<=0)
                return $this->Error(1, 'fromtitle too short');
        if (strlen($title)>=128)
                return $this->Error(1, 'fromtitle too long');
        $this->mailfromtitle=$title;
        return true;
        }

function AddAttachment($type, $data, $name)
        {
        // THIS WILL TAKE ATTACHMENTS, BUT WON'T YET MAIL THEM.
        $insert=sizeof($this->attachements);
        $this->attachements[$insert][data]=$data;
        $this->attachements[$insert][type]=$type;
        $this->attachements[$insert][name]=$name;
        return false;
        }

Function BuildBody($MIMEType)
        {
        // Take the text, add any attachements, doc type, etc.
        // attachments currently don't work.

        // SET MIME TYPE
        if ($MIMEType=='text')
                $return.="Content-Type: text/plain; charset=iso-8859-1\r\n";
        elseif($MIMEType=='html')
                $return.="Content-Type: text/html; charset=iso-8859-1\r\n";
        else
                $return.="Content-Type: text/plain; charset=iso-8859-1\r\n";

        // SET TO HEADER
        if (strlen($this->mailtotitle)>=1)
                $return.="To: ".$this->mailtotitle."\r\n";

        // SET FROM HEADER
        if (strlen($this->mailfromtitle)>=1)
                $return.="From: ".$this->mailfromtitle." <".$this->mailfrom.">\r\n";
        else    $return.="From: ".$this->mailfrom."\r\n";

        if (sizeof($this->mailcc)>=1)
                {
                $return.="Cc:";
                for ($i=0; $i<sizeof($this->mailcc); $i++)
                        {
                        if ($i)
                                $return.=", ";
                        $return.=$this->mailcc[$i];
                        }
                $return.="\r\n";
                }

        if (strlen($this->mailsubject)>=1)
                $return.="Subject: ".$this->mailsubject."\r\n";

        $return .="X-Priority: 1\r\n";
        $return .= "\r\n" . $this->mailtext;

        return $return;
        }

Function sendmail($text_type='html')
        {
        if (!$this->sock)
                return $this->error(2);
        else    {
                if (!$body=$this->BuildBody($text_type))
                        return $this->Error(1, 'BuildBody Failed');

                $head[]="HELO ".$this->server;
                $head[]="MAIL FROM:<".$this->mailfrom.">";
                while (list($key, $value)= each($this->mailto))
                        {
                        $head[]="RCPT TO:<$value>";
                        }
                $head[]='DATA';

                reset ($head);

                while (list($key, $value)=each ($head))
                        {
                        fputs($this->sock, $value."\r\n");
                        if (!$this->GetFeedback())
                                return $this->error($this->errno(), "($value)");
                        }

                fputs($this->sock, "$body\r\n.\r\n");
                if (!$this->GetFeedback())
                        return false;
                }
        $this->ResetData();
        return true;
        }

function ResetData()
        {
        $mailto         = array();
        $mailfrom       = "";
        $mailfromtitle  = '';
        $mailsubject    = "";
        $mailtext       = "";
        $attachments    = array();
        return true;
        }


Function GetFeedback()
        {
        if (!$response=fgets($this->sock, $this->readlength))
                return false;
        if ($this->IsOK($response))
                return true;
        else    return false;
        }

Function IsOK ($input)
        {
        // Extract the return code from the SMTP server, and make sure it's a
        // 'yahoo' instead of a 'shucks'.

        if (!ereg("((^[0-9])([0-9]*))", $input, $regs))
                return $this->error(1, 'input');

        $code=$regs[1];

        switch ($code)
                {
                case '220':
                case '221':
                case '250':
                case '251':
                case '354':
                        return true;
                        break;
                default:
                        return $this->error(4, $input);
                        break;
                }
        }

Function end()
        {
        if (!$this->sock)
                return $this->error(3, 'function end');

        fputs($this->sock, "QUIT\r\n");

        if ($this->GetFeedback())
                {
                fclose($this->sock);
                return true;
                }
        else    {
                return false;
                }
        }

} // END OF CLASS...

* * * Courriel protégé par Internet Expresso AntiVirus * * *