note 111562 added to function.imap-append

From: Date: Mon, 04 Mar 2013 21:08:33 +0000
Subject: note 111562 added to function.imap-append
Groups: php.notes 
Request: Send a blank email to php-notes+get-193892@lists.php.net to get a copy of this message
<?php define('PATHATTACHMENT','/var/www/intranet/somefolder/'); function append_mail($text,$fromaddress,$toaddress,$ccaddress,$subject,$tabAttachs,$login, $passwd) { //compose html message with text $tmessage ='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n<html>\n<head>".'<meta http-equiv="Content-Type" content="text/html" charset="iso_8859-1"/>'."\n\n</head>\n<body>\n".$text; $tmessage.="</body>\n</html>\n"; $link = imap_open('{imap.orange.fr:993/ssl/novalidate-cert}', $login, $passwd); if (FALSE === $link) { $err = 'Unable to open connection '. imap_last_error(); } else { /////////////COMPOSE ENVELOPPE/////////////// $envelope["from"]= $fromaddress; $envelope["to"] = $toaddress; $envelope["cc"] = $ccaddress; $envelope["subject"] = $subject; $envelope['date']=date("d-M-Y H:i:s 0"); $part[1]["type"] = TYPEMULTIPART; $part[1]["subtype"] = "mixed"; $part[1]["charset"] = 'iso_8859-1'; ////////////////////TEXT//////////////////// $part[2]["type"] = TYPETEXT; $part[2]["subtype"] = "html"; $part[2]["description"] = $subject; $part[2]["encoding"] = ENCQUOTEDPRINTABLE; $part[2]["contents.data"] = imap_8bit($tmessage)."\r\n"; ////////////////////ATTACHEMENTS///////////////////////////// $i=3; foreach ($tabAttachs as $tabAttach) { $filename = PATHATTACHMENT.$tabAttach; $fp = fopen($filename, "r"); $contents = fread($fp, filesize($filename)); fclose($fp); $part[$i]["type"] = TYPEAPPLICATION; $part[$i]["encoding"] = ENCBINARY; $part[$i]["subtype"] = "octet-stream"; $part[$i]["description"] = $tabAttach; $part[$i]['disposition.type'] = 'attachment'; $part[$i]['disposition'] = array ('filename' => $tabAttach); $part[$i]['type.parameters'] = array('name' => $tabAttach); $part[$i]["contents.data"] = $contents; $i++; } } $mimeMessage = imap_mail_compose($envelope, $part); //compose message //try to append message to mailbox with seen option if (!imap_append($link, "{imap.orange.fr}SENT",$mimeMessage ,"\\Seen")) { //if error $err=imap_last_error(); if (preg_match("/TRYCREATE/",$err)) { //mailbox does not exist imap_createmailbox($link,imap_utf7_encode("SENT"); //try to create mailbox if (!imap_append($link, "{".$server."}".$_POST['mailbox'],$mimeMessage ,"\\Seen")) //retry echo "Unable to copy message to sent mailbox.". imap_last_error(); } } imap_close($link); } } ?> ---- Server IP: 69.147.83.199 Probable Submitter: 90.32.97.221 ---- Manual Page -- http://php.net/manual/en/function.imap-append.php Edit -- https://master.php.net/note/edit/111562 Del: integrated -- https://master.php.net/note/delete/111562/integrated Del: useless -- https://master.php.net/note/delete/111562/useless Del: bad code -- https://master.php.net/note/delete/111562/bad+code Del: spam -- https://master.php.net/note/delete/111562/spam Del: non-english -- https://master.php.net/note/delete/111562/non-english Del: in docs -- https://master.php.net/note/delete/111562/in+docs Del: other reasons-- https://master.php.net/note/delete/111562 Reject -- https://master.php.net/note/reject/111562 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#193892) next »