Forum Webscript.Ru
Программирование => PHP => Тема начата: listopad от 18 Октября 2002, 16:48:38
-
Если использую функцию mail(), как прикрепить файл к письму.... это вообще реально.... ????
-
http://php.spb.ru/php/mail.html
-
Вообще-то мне надо присоединять только изображения.....
А http://php.spb.ru/php/mail.html
у меня не работает, т.к какая-то проблема с сокетами..... хостер masterhost.ru
Вот что пришут логи......
PHP Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of fsockopen(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in /www/apah.php on line 77
Может еще есть варианты.....
-
а ты не используй сокеты ,а используй функцию mail
и вообще, кроме указанного есть миллион других примеров.
зайди на хотскриптс да выбери попроще
-
Поиск по форуму!
-
Пример на PEAR :: Mail (с его подклассами)
include("Mail.php");
include("./Mail/mime.php");
include("./Mail/mail.php");
$params = array("text_charset" => "koi8-r", "text_encoding" => "8bit");
$heads = array("From"=>"max@webscript.ru","Reply-To"=>"max@webscript.ru");
$to = "maximm@inbox.ru";
$mail = new Mail_mime();
$mail->setTXTBody("Test of Mail :: Mime\\r\\nТест кирилицы");
$mail->addAttachment("photo.jpg", \'image/jpeg\');
$body = $mail->get($params);
$hdrs = $mail->headers($heads);
$ml =& Mail::factory(\'mail\');
$ml->send($to, $hdrs, $body);
?>
(если будут траблы с кириллицей - отредактируй конструктор в Pear :: Mail :: mime )
-
[off]И И И не не не стоит стоит стоит писать писать писать одно одно одно и и и тоже тоже тоже три три три раза раза раза.[/off]
-
Макс
весь код составления аттача занимает ровно столько же места, сколько вызов этого класса.
Вот не понимаю я, когда для таких примитивных операций пишут здоровенные классы.
##########################################
#Copyright © 2001 Wanja Hemmerich
# First version published May 2001 - This version August 2001
##########################################
function sendmsg($to, $subject, $text, $from, $file, $type) {
$content = fread(fopen($file,"r"),filesize($file));
$content = chunk_split(base64_encode($content));
$uid = strtoupper(md5(uniqid(time())));
$name = basename($file);
$header = "From: $from\\nReply-To: $from\\n";
$header .= "MIME-Version: 1.0\\n";
$header .= "Content-Type: multipart/mixed; boundary=$uid\\n";
$header .= "--$uid\\n";
$header .= "Content-Type: text/plain\\n";
$header .= "Content-Transfer-Encoding: 8bit\\n\\n";
$header .= "$text\\n";
$header .= "--$uid\\n";
$header .= "Content-Type: $type; name=\\"$name\\"\\n";
$header .= "Content-Transfer-Encoding: base64\\n";
$header .= "Content-Disposition: attachment;
$ilename=\\"$name\\"\\n\\n";
$header .= "$content\\n";
$header .= "--$uid--";
mail($to, $subject, "", $header);
return true;
}
?>
sendmsg() is a function that allows you to send eMails with
attachments. The function is built up like this:
sendmsg(string to, string subject, string body, string from , string path_of_file, string filetype);
Explaination:
1. string to: to which eMailadresse will the eMail with_
attachment be sent.
2. string subject: what subject will the eMail have?
3. string body: will the also have some body text, or just the_
attachment?
4. string from: Who sent the eMail?
5. string path_of_file: which file should be sent. Which path_
does it have?
6. string filetype: which filetype does the file have, that_
should be sent?
Here are some possible filetypes:
image/gif = GIF picture
image/jpeg = JPEG picture
image/png = PNG picture
application/x-zip-compressed = Compressed ZIP
application/x-gzip = Compressed GZ
application/x-tar = Compressed TAR
Here\'s an example how the function should be used:
sendmsg("webmaster@w3secrets.xxx", "Hi Webmaster", "Hi Webmaster!\\n\\nyou have a great script!", "picture.gif", "image/gif");
-
RomikChef
Да ладно тебе, :) очень даже неплохой класс.
я знаю твою нелюбовь к классам в ПХП :)
В данном случае я его предложил потому что:
1. Он (класс) полностью готов к использованию
2. Не нужно знать стандарт MIME (хотя наверное это недостаток для начинающих)
Вот не понимаю я, когда для таких примитивных операций пишут здоровенные классы.
ты думаеш я его писал ? :)