note 55078 added to ref.mail

From: Date: Mon, 25 Jul 2005 08:36:02 +0000
Subject: note 55078 added to ref.mail
Groups: php.notes 
Request: Send a blank email to php-notes+get-92399@lists.php.net to get a copy of this message
hi all! here is a little re-work and upgrade of the function posted by sadikkeskin at hotmail dot com. the function can be used with a form (enctype="multipart/form-data") wich has the fields "text" and as many "input type=file name="attachment[]" " as you desire... it then sends the mail to all the email adresses stored in your database enjoy! Marco <?php $boundary='--' . md5( uniqid("myboundary") ); $priorities = array( '1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)' ); $priority=$priorities[2]; $charset="iso-8859-1"; $ctencoding="8bit"; $sep= chr(13) . chr(10); $disposition="inline"; $from="newsletter@example.com"; $subject = "Newsletter example.com - ".date("d.m.Y",mktime()); //_________________________________header_____________________ $header.="From: $from\nX-Priority: $priority\nCC: $cc\n"; $header.="Mime-Version: 1.0\nContent-Type: multipart/mixed;\n boundary=\"$boundary\"\n"; $header.="Content-Transfer-Encoding: $ctencoding\nX-Mailer: Php/libMailv1.3\n"; //_________________________________header_____________________ //__________________________STARTS FETCHING MySQL EMAILS____________________ //needs a valid MySQL resource ($result) while ($row = mysql_fetch_array($result)){ $mailtext = "Hello $row[name]\r\n".$_POST['text']; $message .="This is a multi-part message in MIME format.\n--$boundary\n"; $message .= "Content-Type: text/plain; charset=$charset\n"; $message .= "Content-Transfer-Encoding: $ctencoding\n\n" . $mailtext ."\n"; foreach($_FILES['attachment']['error'] as $key => $error) { if($error == UPLOAD_ERR_OK) { $filename = $_FILES['attachment']['name'][$key]; $filetype = $_FILES['attachment']['type'][$key]; $message .="--$boundary\nContent-type: $filetype ;\n name=\"$filename\"\n"; $message .="Content-Transfer-Encoding: base64\nContent-Disposition: $disposition;\n filename=\"$filename\"\n"; $linesz= filesize( $_FILES['attachment']['tmp_name'][$key])+1; $fp= fopen( $_FILES['attachment']['tmp_name'][$key], 'r' ); $content = chunk_split(base64_encode(fread( $fp, $linesz))); fclose($fp); $message .= $sep.$content; } } // sends the mail to each member of the newsletter $sended = mail($row['email'], $subject, $message, $header); if ($sended){$emails.= $row['email'].", ";} } //__________________________END FETCHING MySQL EMAILS____________________ //removes the last ", " $emails = substr($emails,0,strlen($emails)-2); // prints the adresses the mail was succesfully send to print "<p>Your message has been sent to the following addresses: $emails</p>"; print "<div align ='right'><a href='javascript: history.go(-1);'>Back</a></div>"; ?> ---- Manual Page -- http://www.php.net/manual/en/ref.mail.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55078 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55078&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55078&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55078&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55078&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55078&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55078&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55078&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92399) next »