embeded html email

From: Date: Mon, 14 Aug 2000 20:01:33 +0000
Subject: embeded html email
Groups: php.general 
Request: Send a blank email to php-general+get-11626@lists.php.net to get a copy of this message
Looking for some help running a script that uses embeded html. I have been using Richard Heyes html_mime_class and so far all of the script works except it doesn't sned and I'm not certain why. <? /* * Class mime_mail * Original implementation by Sascha Schumann <sascha@schumann.cx> * Modified by Tobias Ratschiller <tobias@dnet.it>: * - General code clean-up * - separate body- and from-property * - killed some mostly un-necessary stuff */ class mime_mail { var $parts; var $to; var $from; var $headers; var $subject; var $body; /* * void mime_mail() * class constructor */ function mime_mail() { $this->parts = array(); $this->to = ""; $this->from = ""; $this->subject = ""; $this->body = ""; $this->headers = ""; } /* * void add_attachment(string message, [string name], [string ctype]) * Add an attachment to the mail object */ function add_attachment($message, $name = "", $ctype = "application/octet-stream") { $this->parts[] = array ( "ctype" => $ctype, "message" => $message, "encode" => $encode, "name" => $name ); } /* * void build_message(array part= * Build message parts of an multipart mail */ function build_message($part) { $message = $part["message"]; $message = chunk_split(base64_encode($message)); $encoding = "base64"; return "Content-Type: ".$part["ctype"]. ($part["name"]?"; name = \"".$part["name"]."\"" : ""). "\nContent-Transfer-Encoding: $encoding\n\n$message\n"; } /* * void build_multipart() * Build a multipart mail */ function build_multipart() { $boundary = "b".md5(uniqid(time())); $multipart = "Content-Type: multipart/mixed; boundary = $boundary\n\nThis is a MIME encoded message.\n\n--$boundary"; for($i = sizeof($this->parts)-1; $i >= 0; $i--) { $multipart .= "\n".$this->build_message($this->parts[$i])."--$boundary"; } return $multipart.= "--\n"; } /* * void send() * Send the mail (last class-function to be called) */ function send() { $mime = ""; if (!empty($this->from)) $mime .= "From: ".$this->from."\n"; if (!empty($this->headers)) $mime .= $this->headers."\n"; if (!empty($this->body)) $this->add_attachment($this->body, "", "text/html; charset=iso-8859-1"); $mime .= "MIME-Version: 1.0\n".$this->build_multipart(); mail($this->to, $this->subject, "", $mime); } }; // end of class ?> <? error_reporting(63); include("smtp_class.inc.php"); include('mime_class3.inc.php'); require("dbconect.inc.php"); /*************************************** ** Create the mail object. Optional headers ** argument. Do not put From: here, this ** will be added when $mail->send ***************************************/ $mail = new html_mime_mail("X-Mailer: Html Mime Mail Class\r\n"); /*************************************** ** If sending an html email, then these ** two variables specify the text and ** html versions of the mail. Don't ** have to be named as these are. Just ** make sure the names tie in to the ** $mail->add_html() command further down. ***************************************/ $text = 'Success.'; $html = '<HTML> $body </HTML>'; /************************************* ** misc functions ** **************************************/ function send_mail($emailady, $from, $subject, $body){ $mailHeaders="$emailady"; $path_to_sendmail = "/usr/lib/sendmail"; $fp = popen("$path_to_sendmail -t", "w"); $num = fputs($fp, "To: $emailady \n"); $num += fputs($fp, "From: $from \n"); $num += fputs($fp, "Subject: $subject\n\n"); $num += fputs($fp, "$body"); pclose($fp); } trim($realname); trim($businessname); trim($domain); trim($emailady); $result = pg_exec($db, "INSERT INTO opensrs (custname, businessname, domain, email, reg_trans, consent ) VALUES ('$realname', '$businessname', '$domain', '$emailady', '$reg_trans', '$consent' );"); $to_name = '$realname'; $to_addr = "$emailady"; $from_name = "dns@vianet.on.ca ViaNet Hostmaster"; $from = "dns@vianet.ca"; $subject = "OpenSRS Agreement for $domain"; /************************************** **builds the body of the email ** **************************************/ $url = "http://via2k.vianet.ca/scripts/admin/agreement.php?domain=$domain"; $body = " <p>$reg_trans of the domain $domain is currently in process."; $body .= " Before this $reg_trans can be completed, you must read and"; $body .= " agree to the service agreement governing this transaction.</p><p>Please follow"; $body .= " this URL: <a href=$url>OpenSRS agreement for $domain</a>"; $body .= " and read the terms of the agreement. If you agree with the terms of this"; $body .= " agreement, check the button marked \"Yes\" and click on the \"Submit\" button."; $body .= " If you do not agree with the terms of this agreement, please check the"; $body .= " button marked \"No\" and click on the \"Submit\" button. We will only proceed"; $body .= " with your $reg_trans if you agree to the terms and conditions"; $body .= " as laid out in that agreement. Either a No response or failure to respond"; $body .= " within 10 days will result your $reg_trans process being"; $body .= " discontinued.</p>"; $body .= " ViaNet Hostmaster"; /*************************************** ** Add the text, html and embedded images. ** Each embedded image has to be added ** using $mail->add_html_image() BEFORE ** calling $mail->add_html(). The name ** of the image should match exactly ** (case-sensitive) to the name in the html. ***************************************/ file://$mail->add_html_image($backgrnd, 'background.gif', 'image/gif'); $mail->add_html($html, $text); /*************************************** ** This is used to add an attachment to ** the email. ***************************************/ file://$mail->add_attachment($attachment, 'example.zip', 'application/octet-stream'); /*************************************** ** Builds the message. ***************************************/ $mail->build_message(); /*************************************** ** Sends the message. $mail->build_message() ** is seperate to $mail->send so that the ** same email can be sent many times to ** differing recipients simply by putting ** $mail->send() in a loop. ***************************************/ file://$mail->send('$to_name', '$to_addr', '$from_name', '$from_addr', '$subject'); $mail->send($realname, $emailady, 'dns registration', 'dns@vianet.ca', $subject); /*************************************** ** Debug stuff. Entirely unnecessary. ***************************************/ /* echo '<PRE>'; echo $mail->mime; echo '</PRE>'; */ /* echo "$to_name <br>"; echo "$from_name <br>"; echo "$from_addr <br>"; echo "$subject <br>"; echo "$realname"; echo "$emailady"; */ ?>

« previous php.general (#11626) next »