note 51628 added to function.mail

From: Date: Wed, 06 Apr 2005 00:05:09 +0000
Subject: note 51628 added to function.mail
Groups: php.notes 
Request: Send a blank email to php-notes+get-87547@lists.php.net to get a copy of this message
A comfortable way to redirect an email : (Obviously there are other ways to redirect, but this could save someone a lot of hassle. ) If all you want to do is redirect an email and you want to do it from the comfort of the mail() and imap_X() functions then surprisingly mail() will successfully send an email to your chosen destination with the contents intact (text/mime/multipart whatever) by just dumping the result of imap_fetchheader into the header parameter and dumping imap_body into the body parameter. For example : <?php $header=imap_header($mbox,1); mail('somechap@somewhere.com',$header->Subject,imap_body($mbox,1), imap_fetchheader($mbox,1)); ?> Notice that you still have to transfer the subject line manually using imap_header. One note, however, is that it may be possible on particular platforms that the header info might have had its CRLFs mangled and so this technique might need adjustment if you are unlucky. Also note that this is a somewhat surprising method, and one might be (wisely) circumspect about using a technique that could be broken by an unfortunate updating of mail(). However I don't believe this is a significant concern as the mail() function is very simple in what it offers, such that the likelyhood of broken code is about as minimal as can be expected. However apps that need to be industrially strong should probably not use this technique. Greg http://www.lorriman.com ---- Manual Page -- http://www.php.net/manual/en/function.mail.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51628 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51628&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51628&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51628&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51628&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51628&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51628&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#87547) next »