|
|
|
|
|
для: cccp
(03.08.2005 в 22:44)
| | Давайте всё-таки отталкиваться от рабочего скрипта http://www.softtime.ru/scripts/mailattach.php, а не от нерабочего :)))
<HTML>
<HEAD>
<TITLE>Отправка сообщения с вложением</TITLE>
</HEAD>
<BODY>
<H3> <center><font color=#1E90FF>Отправка сообщения с вложением</font></H3>
<center>
<table width=1 border=0>
<form action="mail.php" enctype='multipart/form-data' name="mailform" method="post" target="sendmail">
<input type=text name=mail_to maxlength=32>
<input type=text name=mail_subject maxlength=64>
<input type=file name=mail_file maxlength=64>
<input name="prenom" id="prenom" type="text" value="Prénom" onClick="clearmailform(prenom);">
<input name="mail" id="mail" type="text" value="adresse E-mail" onClick="clearmailform(mail);">
<input name="date" id="date" type="text" value="date de naissance" onClick="clearmailform(date);">
<input name="cheveux" id="cheveux" type="text" value="couleur de cheveux" onClick="clearmailform(cheveux);">
<input name="yeux" id="yeux" type="text" value="couleur de yeux" onClick="clearmailform(yeux);">
<input name="taille" id="taille" type="text" value="taille" onClick="clearmailform(taille);">
<textarea name="expirience" id="textarea" cols="60" rows="04" wrap="VIRTUAL" onFocus="if(this.value=='Votre expirience...')this.value='';">Votre expirience...</textarea>
<textarea name="lettre" cols="60" rows="04" wrap="VIRTUAL" onFocus="if(this.value=='Votre message...')this.value='';">Votre message...</textarea>
<input type=file name=mail_file maxlength=64>
<input type=submit value='Отправить'>
</form>
</form>
</table>
</center>
</BODY>
</HTML>
|
Тогда mail.php может выглядеть следующим образом
<?php
if(empty($_POST['mail_to'])) exit("Введите адрес получателя");
// проверяем правильности заполнения с помощью регулярного выражения
if (!preg_match("/^[0-9a-z_]+@[0-9a-z_^\.]+\.[a-z]{2,3}$/i", $_POST['mail_to'])) exit("Введите адрес в виде somebody@server.com");
$_POST['mail_to'] = htmlspecialchars(stripslashes($_POST['mail_to']));
$_POST['mail_subject'] = htmlspecialchars(stripslashes($_POST['mail_subject']));
$_POST['mail_msg'] = htmlspecialchars(stripslashes($_POST['mail_msg']));
$_POST['mail_msg'] .= "name - ".$_POST['name']."<br>";
$_POST['mail_msg'] .= "mail - ".$_POST['mail']."<br>";
$_POST['mail_msg'] .= "date - ".$_POST['date']."<br>";
$_POST['mail_msg'] .= "cheveux - ".$_POST['cheveux']."<br>";
$_POST['mail_msg'] .= "yeux - ".$_POST['yeux']."<br>";
$_POST['mail_msg'] .= "taille - ".$_POST['taille']."<br>";
$_POST['mail_msg'] .= "lettre - ".$_POST['lettre']."<br>";
$picture = "";
// Извлекаем из имени файла расширение
$ext = strrchr($_FILES['mail_file']['name'], ".");
// Разрешаем загружать файлы только определённого форматм
$extentions = array(".jpg",".gif");
// Формируем путь к файлу
if(!in_array($ext, $extentions)) exit("Недопустимый формат файла");
// Если поле выбора вложения не пустое - закачиваем его на сервер
if (!empty($_FILES['mail_file']['tmp_name']))
{
// Закачиваем файл
$path = $_FILES['mail_file']['name'];
if (copy($_FILES['mail_file']['tmp_name'], $path)) $picture = $path;
}
$thm = $_POST['mail_subject'];
$msg = $_POST['mail_msg'];
$mail_to = $_POST['mail_to'];
// Отправляем почтовое сообщение
if(empty($picture)) mail($mail_to, $thm, $msg);
else send_mail($mail_to, $thm, $msg, $picture);
// Вспомогательная функция для отправки почтового сообщения с вложением
function send_mail($to, $thm, $html, $path)
{
$fp = fopen($path,"r");
if (!$fp)
{
print "Файл $path не может быть прочитан";
exit();
}
$file = fread($fp, filesize($path));
fclose($fp);
$boundary = "--".md5(uniqid(time())); // генерируем разделитель
$headers .= "MIME-Version: 1.0\n";
$headers .="Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
$multipart .= "--$boundary\n";
$kod = 'koi8-r'; // или $kod = 'windows-1251';
$multipart .= "Content-Type: text/html; charset=$kod\n";
$multipart .= "Content-Transfer-Encoding: Quot-Printed\n\n";
$multipart .= "$html\n\n";
$message_part = "--$boundary\n";
$message_part .= "Content-Type: application/octet-stream\n";
$message_part .= "Content-Transfer-Encoding: base64\n";
$message_part .= "Content-Disposition: attachment; filename = \"".$path."\"\n\n";
$message_part .= chunk_split(base64_encode($file))."\n";
$multipart .= $message_part."--$boundary--\n";
if(!mail($to, $thm, $multipart, $headers))
{
echo "К сожалению, письмо не отправлено";
exit();
}
}
?>
|
| |
|
|
|
|
|
|
| Ребята , помогите откориктировать, пожалуста.
Я сам пробовал собрать свою версию, но вы быстро поймёте что я не АС в этом деле...хотя и стараюсь.
Тут где то ошибки (и может их там полно).
Зарание спасибо.
<form action="mail.php" name="mailform" method="post" target="sendmail">
<input name="prenom" id="prenom" type="text" value="Prénom" onClick="clearmailform(prenom);">
<input name="mail" id="mail" type="text" value="adresse E-mail" onClick="clearmailform(mail);">
<input name="date" id="date" type="text" value="date de naissance" onClick="clearmailform(date);">
<input name="cheveux" id="cheveux" type="text" value="couleur de cheveux" onClick="clearmailform(cheveux);">
<input name="yeux" id="yeux" type="text" value="couleur de yeux" onClick="clearmailform(yeux);">
<input name="taille" id="taille" type="text" value="taille" onClick="clearmailform(taille);">
<textarea name="expirience" id="textarea" cols="60" rows="04" wrap="VIRTUAL" onFocus="if(this.value=='Votre expirience...')this.value='';">Votre expirience...</textarea>
<textarea name="lettre" cols="60" rows="04" wrap="VIRTUAL" onFocus="if(this.value=='Votre message...')this.value='';">Votre message...</textarea>
<input name="photos" type="file" id="photos" maxlength="64" value="photos" onclick="clearmailform(photos);">
</form>
|
<?php
include("data/config.inc.php");
if($_POST['mail']=="" or $_POST['mail']=="[Votre boite]") {
$mess="Vous devez indiquer votre <u>Adresse E-mail</u>!"; $title="Erreur!";
} elseif(!strstr($_POST['mail'],"@") or !strstr($_POST['mail'],".")) {
$mess="Votre adresse <u>exacte</u> est nécéssaire pour l'envoi de votre message."; $title="Erreur!";
} elseif (!isset($_POST['date']) or $_POST['date']=="") {
$mess="Votre date de naissance est nécéssaire</u> pour effectuer l'envoi de cette lettre..."; $title="Erreur!";
} elseif (!isset($_POST['cheveux']) or $_POST['cheveux']=="") {
$mess="Votre couleur de cheveux est nécéssaire</u> pour effectuer l'envoi de cette lettre..."; $title="Erreur!";
} elseif (!isset($_POST['yeux']) or $_POST['yeux']=="") {
$mess="Votre couleur de yeux est nécéssaire</u> pour effectuer l'envoi de cette lettre..."; $title="Erreur!";
} elseif (!isset($_POST['taille']) or $_POST['taille']=="") {
$mess="Votre taille est nécéssaire</u> pour effectuer l'envoi de cette lettre..."; $title="Erreur!";
} elseif (!isset($_POST['expirience']) or $_POST['expirience']=="") {
$mess="Votre expirience est nécéssaire</u> pour effectuer l'envoi de cette lettre..."; $title="Erreur!";
} elseif (!isset($_POST['lettre']) or $_POST['lettre']=="") {
$mess="Votre <u>message est nécéssaire</u> pour effectuer l'envoi de cette lettre..."; $title="Erreur!";
} elseif (!isset($_POST['photos']) or $_POST['photos']=="") {
$mess="Vos photos sont nécéssaire</u> pour effectuer l'envoi de cette lettre..."; $title="Erreur!";
$picture = "";
// Izvlekaem iz imeni fajla rasshirenie
$ext = strrchr($_FILES['photos']['name'], ".");
// Razreshaem zagruzhat' fajly tol'ko opredeljonnogo formatm
$extentions = array(".jpg",".gif");
// Formiruem put' k fajlu
if(!in_array($ext, $extentions)) exit("Le format du fichier n'est pas acceptable !");
// Esli pole vybora vlozhenija ne pustoe - zakachivaem ego na server
if (!empty($_FILES['photos']['tmp_name']))
{
// Zakachivaem fajl
$path = $_FILES['photos']['name'];
if (copy($_FILES['photos']['tmp_name'], $path)) $picture = $path;
{
$fp = fopen($path,"r");
if (!$fp)
{
print "Votre fichier $path ne peut pas etre accepter!";
exit();
}
$file = fread($fp, filesize($path));
fclose($fp);
$path = substr($path,12);
} else {
if(!isset($_POST['prenom']) or $_POST['prenom']=="[Votre nom]") $_POST['prenom']="anonymous";
$boundary = "--".md5(uniqid(time())); // generiruem razdelitel'
$body=strip_tags($_POST['lettre']);
$headers ="From: ".strip_tags($_POST['prenom'])."<".strip_tags($_POST['mail']).">\n";
$headers.="MIME-Version: 1.0\n";
$headers .="Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
$multipart .= "--$boundary\n";
$kod = 'koi8-r'; // ili $kod = 'windows-1251';
$multipart .= "Content-Type: text/html; charset=$kod\n";
$multipart .= "Content-Transfer-Encoding: Quot-Printed\n\n";
$multipart .= "$html\n\n";
$message_part = "";
$message_part .= "Content-Type: application/octet-stream";
$message_part .= "; file_name = \"$path\"\n";
$message_part .= "Content-Transfer-Encoding: base64\n";
$message_part .= "Content-Disposition: attachment; filename = \"".$path."\"\n\n";
$message_part .= chunk_split(base64_encode($file))."\n";
$multipart .= "--$boundary\n".$message_part."--$boundary--\n";
$sign=array("\r","\n");
$ch=array("","");
mail($sendmail,$sendtheme,$body,$headers,$path);
$mess="<font color='#cccccc' size='2'><br><br><br><br>Votre message a été envoyé avec succes!<br>Merci.</font>"; $title="Message envoyé avec succes!"; $sent="ok";
}
?>
<html>
<head><title><?php echo $title; ?></title><meta http-equiv="Content-Type" content="text/html; charset=windows-1250"></head>
<style>
a:link {color:blue; text-decoration:none; font-size:11px;}
a:visited {color:blue; text-decoration:none; font-size:11px;}
a:hover {color:#A8A8A8; text-decoration:none; font-size:11px;}
a:active {color:#A8A8A8; text-decoration:none; font-size:11px;}
.mess {font-family:verdana;font-size:12px;text-align:center;}
</style>
<BODY bgcolor="5E514A" style="scrollbar-face-color:#5E514A;scrollbar-track-color:#5E514A;scrollbar-shadow-color:#392F2A;scrollbar-highlight-color:#392F2A;scrollbar-3dlight-color:#5E514A;scrollbar-darkshadow-color:#79665D">
<?php
if(isset($sent) and $sent=="ok") echo '<p class="mess"><b>'.$mess.'</b>';
else echo '<p class="mess"><b><font color=red><br><br><br><br>Erreur: </font>'.$mess.'</b>';
?>
<div align="center"></div>
<div align="center"></div>
<div align="center"></div>
<p align="center"><br>
<br>
<a href="show_form.php" title=<?php echo $_SERVER['HTTP_REFERER']; ?>><font color="#999999" face="Arial, Helvetica, sans-serif">[retour]</font></a><font face="Arial, Helvetica, sans-serif"><br>
<A href=# onclick="window.close()"><font color="#999999">fermer</font></A></font></p>
</body>
</html>
|
| |
|
|
|
|