ارسال فايل در فرم تماس با ما

NojanServer

Member
دوستان عزيز سلام
كسي يك فرم تماس با ما داره كه توي اون بشه فايل هم ارسال كرد ؟

مثلا :

نام :
نام خانوادگي :
شماره شناسنامه :
كشور :
كپي شناسنامه : اين قسمت بايد كپي اسكن و attach بشه
توضيحات :

خيلي ممنون ميشم اگه راهنمايي كنيد.:wink:
 

PC man

Active Member
کد:
function emailUs() {
1
    if(isset($_POST['action']) && $_POST['action'] == 'SEND_MAIL') {
2
        echo "              SENDING EMAIL...<br />n";
3
        if(sendMyMail()) echo "              EMAIL SENT.<br /><br />n";
4
    }
5
?>
6
      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="form">
7
      <form name="email" method="post" action="<?php echo "$_SERVER[PHP_SELF]"; if(isset($_GET['menu'])) echo "?menu=$_GET[menu]"; if(isset($_GET['subMenu'])) echo "&amp;subMenu=$_GET[subMenu]"; ?>" enctype="multipart/form-data">
8
        <tr>
9
          <td>
10
<?php
11
        if(!isset($_SESSION['userID'])) {
12
?>
13
            YOUR NAME: <input type="text" name="mailer" size="40" value="<?php echo $_SESSION['userID']; ?>" /><br /><br />                    
14
            YOUR EMAIL: <input type="text" name="mail_from" size="40" value="<?php echo $_SESSION['email']; ?>" /><br /><br />
15
<?php
16
        }
17
?>
18
            SUBJECT: <input type="text" name="e_subject" size="40" maxlength="80" /><br /><br />
19
            MESSAGE:<br /><textarea name="e_message" cols="40" rows="10"></textarea><br />
20
<?php
21
        if(isset($_SESSION['userID'])) {
22
            echo "                    FILE(s):<br />n";
23
            for($i = 0; $i < 4; $i++) {
24
                echo "            <input type="file" name="myFile{$i}" size="40" /><br />n";
25
            }
26
        }
27
?>
28
          </td>
29
        </tr>
30
        <tr>
31
          <td align="right">
32
            <input type="hidden" name="action" value="SEND_MAIL" />
33
            <input type="submit" name="submit" value="submit" class="button" />
34
          </td>
35
        </tr>
36
      </form>
37
      </table>
38
<?php    
39
} // END emailUs
40

41
function sendMyMail(){
42
    $mail_to = "[email protected]";
43

44
    if(!isset($_SESSION['userID'])) {
45
        if(!empty($_POST['mailer'])) $mailerID = $_POST['mailer'];
46
        else {
47
            echo "              CANNOT SEND EMAIL WITHOUT SENDERS NAME!<br /><br />n";
48
            echo "              ABORTING TRANSMISSION...<br /><br />n";
49
            return 0;
50
        }
51
        
52
        if(!empty($_POST['mail_from'])) $mail_from = $_POST['mail_from'];
53
        else {
54
            echo "              CANNOT SEND EMAIL WITHOUT SENDERS EMAIL ADDRESS!<br /><br />n";
55
            echo "              ABORTING TRANSMISSION...<br /><br />n";
56
            return 0;
57
        }
58
        if(!eregi("^[a-z0-9]+([_.-][a-z0-9]+)*@([a-z0-9]+([.-][a-z0-9]+)*)+(.[a-z]{2,})$",$_POST['mail_from'],$regs)) {
59
            echo "              THE EMAIL ADDRESS ENTERED: ("".$_POST['mail_from']."") IS NOT A VALID FORMAT!<br /><br />n";
60
            echo "              ABORTING TRANSMISSION...<br /><br />n";
61
            return 0;
62
        }
63
    }
64
    else {
65
         $mailerID = $_SESSION['userID'];
66
         $mail_from = $_SESSION['email'];
67
    }        
68
    
69
    $e_subject = stripslashes($_POST['e_subject']);    
70
    $e_message = stripslashes($_POST['e_message']);
71
    
72
    $border_random = md5(time());
73
    
74
    $mail_boundary = "x{$border_random}x";
75
    
76
    $new_e_message = "From: {$mailerID} <{$mail_from}>rn";
77
    $new_e_message .= "To: {$mail_to}rn";
78
    $new_e_message .= "Reply-to: {$mail_from}rn";    
79
    $new_e_message .= "MIME-Version: 1.0rn";
80
    $new_e_message .= "Content-type: multipart/mixed; boundary="{$mail_boundary}"rn";
81
    $new_e_message .= "This is a multi-part message in MIME format.rnrn";
82
    $new_e_message .= "--{$mail_boundary}rn";
83
    $new_e_message .= "Content-type: text/plain; charset="iso-8859-1"rn";
84
    $new_e_message .= "Content-Transfer-Encoding:7bitrnrn";
85
    $new_e_message .= "{$e_message}rnrn";
86
         
87
    for ($i = 0; $i < 4; $i++) {
88
        
89
        $myFile{$i} = $_FILES['myFile'.$i]['tmp_name'];
90
        
91
        if (is_uploaded_file($myFile{$i})) {
92
            
93
            $myFile_type = $_FILES['myFile'.$i]['type'];
94
            $myFile_name = $_FILES['myFile'.$i]['name'];
95
            $myFile_size = $_FILES['myFile'.$i]['size'];
96
            
97
            $fp = fopen($myFile{$i},"rb");
98
            $fileData = fread($fp,$myFile_size);
99
            fclose($fp);
100
            
101
            $file = base64_encode($fileData);
102
            $file = chunk_split($file);
103
            
104
            $new_e_message .= "--{$mail_boundary}rn";
105
            $new_e_message .= "Content-type: {$myFile_type}; name="{$myFile_name}"rn";
106
            $new_e_message .= "Content-Transfer-Encoding:base64rn";
107
            $new_e_message .= "Content-Disposition: attachment; filename="{$myFile_name}"rnrn";
108
            $new_e_message .= $file."rnrn";
109
            
110
        }
111
    }
112
    $new_e_message .= "--{$mail_boundary}--rn";
113
           
114
    $e_body = "";
115
    
116
    $e_message = $new_e_message;  
117
        
118
    $send = mail($mail_to,$e_subject,$e_body,$e_message);
119
    
120
    if($send) return 1;
121

122
    else {
123
        echo "              EMAIL COULD NOT BE SENT FOR UNKNOWN REASONS!<br /><br />n";
124
        return 0;
125
    }
126
} // END sendMyMail
[/code[
 

arashdanger

Member
این برنامه فایل رو با تابع base64_encode کد میکنه و برای مطابقت با RFC 2045 اون رو با تابع chunk_split فرمت میکنه البته اینکار بصورت تئوری درسته و احتمالا خیلی از فایلها رو میشه با این روش فرستاد و احتمالا فایل بصورت attachment هم نشون داده میشه ولی احتمالا فایلهای با سایز بزرگ و یا فایلهای باینری با این روش مشکل خواهند داشت. برای حل این مشکل پینهاد میکنم از بسته MAIL در کتابخانه PEAR استفاده کنید.
 

NojanServer

Member
سلام
pc man جان دست شما درد نكنه حالا من چي كار كنم مشكلي كه arashdanger براي من پيش مي ياد يا نه ؟؟؟
 

جدیدترین ارسال ها

بالا