note 38832 added to ref.mail
| From: | GABZinOZ at rn2 dot php dot net | Date: | Thu, 08 Jan 2004 06:11:36 +0000 |
| Subject: | note 38832 added to ref.mail | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-63127@lists.php.net to get a copy of this message | ||
you might want to send some attachments (mainly JPG or GIF files) or anything else generated by an
HTML-form via PHP. I couldn't find anything suitable in the mailing list so here we go:
-------------------------------------------------
$email_address = "Recievers email";
$email_from = "Senders email";
$subject = "Any subject you like!";
$msg = "Text message shown in email";
$attach_filepath = "path to existing picture files. Should be an array!";
-------------------------------------------------
function xmail($email_address,$email_from,$subject,$msg,$attach_filepath) {
$b = 0;
$mail_attached = "";
$boundary = md5(uniqid(time(),1))."_xmail";
if (count($attach_filepath)>0) {
for ($a=0;$a<=count($attach_filepath);$a++) {
if ($fp = fopen($attach_filepath[$a],"rb")) {
$file_name = basename($attach_filepath[$a]);
$content[$b] = fread($fp,filesize($attach_filepath[$a]));
$mail_attached .= "--".$boundary."\r\n"
."Content-Type: image/jpeg; name=\"$file_name\"\r\n"
. "Content-Transfer-Encoding: base64\r\n"
. "Content-Disposition: inline;
filename=\"$file_name\"\r\n\r\n"
.chunk_split(base64_encode($content[$b]))."\r\n";
$b++;
fclose($fp);
} else {
echo "NEIN";
}
}
$mail_attached .= "--".$boundary." \r\n";
$add_header ="MIME-Version: 1.0\r\nContent-Type: multipart/mixed;
boundary=\"$boundary\"";
$mail_content = "--".$boundary."\r\n"
. "Content-Type: text/plain; charset=iso-8859-1;
format=flowed\r\n"
. "Content-Transfer-Encoding: 8bit\r\n\r\n"
. $msg."\r\n\r\n".$mail_attached;
return mail($email_address,$subject,$mail_content,"From:
".$email_from."\r\n".$add_header);
} else {
return mail($email_address,$subject,$msg,"From: ".$email_from);
}
}
----
Manual Page -- http://www.php.net/manual/en/ref.mail.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38832
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38832&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38832&report=yes
Search -- http://master.php.net/manage/user-notes.php