PHP Classes

File: funWithSMTP.php

Recommend this page to a friend!
  Classes of Pierre Marceau   funWithSMTP   funWithSMTP.php   Download  
File: funWithSMTP.php
Role: ???
Content type: text/plain
Description: The whole thing
Class: funWithSMTP
Talk directly to an SMTP server to send e-mail.
Author: By
Last change:
Date: 22 years ago
Size: 1,841 bytes
 

Contents

Class file image Download
<?php class funWithSMTP{ var $fp; function send($data){ echo nl2br($data)."<br>\n"; fputs($this->fp, $data."\r\n"); $this->recv(); } function recv(){ $response=fgets($this->fp, 512); list ($errno, $errmsg) = split (" ", $response); if ($errno<500){ echo "<font color=\"blue\">$response</font>\n<br>"; }else{ echo "<font color=\"red\">$response</font>\n<br>"; exit; } } function open($smtpserver,$ti=2){ $this->fp = fsockopen($smtpserver, 25, $errno, $errstr, $ti); if (!$this->fp){ echo "<b>Error opening $smtpserver</b><br><font color=\"red\">$errstr ($errno).</font><hr>\n"; exit; } $this->recv(); } function close(){ fclose($this->fp); } } $fun = new funWithSMTP; // Just starting? Edit these three lines. // =============================================== $to = '"Buggs Bunny" <buggs@looneytoons.com>'; $from = '"Elmer Fudd" <efudd@looneytoons.com>'; $mySMTPserver = 'my.workingSMTPserver.com'; // =============================================== $header.="Date: 27 Jan 2002 15:01:01 EDT\r\n"; $header.="From: $from\r\n"; $header.="To: $to\r\n"; $header.="Subject: This is fun!\r\n"; $header.="Date: Wed, 17 Apr 2002 20:52:23 -0400\r\n"; $header.="Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"; $header.="Content-Transfer-Encoding: 7bit\r\n"; $header.="X-Priority: 3\r\n"; $separator="\r\n"; $body.="Whats up doc?\r\n"; $body.="Ain't I a little stinker?\r\n"; $terminator="."; $theEmailText = $header.$separator.$body.$terminator; $fun->open($mySMTPserver); $fun->send("HELO looneytunes.com"); $fun->send("MAIL FROM:$from"); $fun->send("RCPT TO:$to"); $fun->send("DATA"); $fun->send($theEmailText); $fun->send("RSET"); $fun->send("QUIT"); $fun->close(); ?>