SMTP::Mail PHP Method

Mail() public method

Implements rfc 821: MAIL FROM: SMTP CODE SUCCESS: 250 SMTP CODE SUCCESS: 552,451,452 SMTP CODE SUCCESS: 500,501,421
public Mail ( $from ) : boolean
return boolean
    public function Mail($from)
    {
        $this->error = null;
        // so no confusion is caused
        if (!$this->connected()) {
            $this->error = array('error' => 'Called Mail() without being connected');
            return false;
        }
        $useVerp = $this->do_verp ? 'XVERP' : '';
        fwrite($this->smtp_conn, 'MAIL FROM:<' . $from . '>' . $useVerp . $this->CRLF);
        $rply = $this->get_lines();
        $code = substr($rply, 0, 3);
        if ($this->do_debug >= 2) {
            echo 'SMTP -> FROM SERVER:' . $rply . $this->CRLF . '<br />';
        }
        if ($code != 250) {
            $this->error = array('error' => 'MAIL not accepted from server', 'smtp_code' => $code, 'smtp_msg' => substr($rply, 4));
            if ($this->do_debug >= 1) {
                echo 'SMTP -> ERROR: ' . $this->error['error'] . ': ' . $rply . $this->CRLF . '<br />';
            }
            return false;
        }
        return true;
    }

Usage Example

Esempio n. 1
0
 function smtp_send($header, $body)
 {
     include "smtp.inc.php";
     // Load code only if asked
     $smtp = new SMTP();
     $smtp->do_debug = $this->SMTPDebug;
     // Try to connect to all SMTP servers
     $hosts = explode(";", $this->Host);
     $x = 0;
     $connection = false;
     while ($x < count($hosts)) {
         if ($smtp->Connect($hosts[$x], $this->Port, $this->Timeout)) {
             $connection = true;
             break;
         }
         // printf("%s host could not connect<br>", $hosts[$x]); //debug only
         $x++;
     }
     if (!$connection) {
         $this->error_handler("SMTP Error: could not connect to SMTP host server(s)");
     }
     $smtp->Hello($this->Helo);
     $smtp->Mail(sprintf("<%s>", $this->From));
     for ($x = 0; $x < count($this->to); $x++) {
         $smtp->Recipient(sprintf("<%s>", $this->to[$x][0]));
     }
     for ($x = 0; $x < count($this->cc); $x++) {
         $smtp->Recipient(sprintf("<%s>", $this->cc[$x][0]));
     }
     for ($x = 0; $x < count($this->bcc); $x++) {
         $smtp->Recipient(sprintf("<%s>", $this->bcc[$x][0]));
     }
     $smtp->Data(sprintf("%s%s", $header, $body));
     $smtp->Quit();
 }
All Usage Examples Of SMTP::Mail