2011-06-04 112 views
0

我有一個工作的PHP郵件,我喜歡,但它只是缺少一件事: 附件文件。我需要一些幫助與PHP郵件(附加文件)

這是我的形式:

<?php get_header(); ?> 
    <form action="http://www.guitara.co.il/wp-content/themes/mguitara/mailEngineThing.php" method="post" id="advfree_new" class="validate" > 

    <div class="field"> 
    <label>שם ומשפחה</label> 
    <input type="text" name="name" id="name" placeholder="ישראל ישראלי" class="required min-length_5 namespace" title="אנא בדוק שהזנת נכון שם ושם משפחה‫.‬"/> 
    </div> 

    <div class="field"> 
    <label>דואר אלקטרוני</label> 
    <input type="email" name="email" id="email" placeholder="[email protected]" class="required email" title="אנא הזן כתובת דואר אלקטרוני תקנית‫.‬"/> 
    </div> 

    <div class="field"> 
    <label>פלאפון</label> 
    <input type="tel" name="phone" id=" phone" placeholder="050-0000000" class="required min-length_10 max-length_11" title="אנא הזן מספר פלאפון ‫(‬בעל 10 ספרות‫).‬"/> 
    </div> 

    <div class="field"> 
    <label>ערים בהם השיעורים מועברים</label> 
    <input type="text" name="citys" id="citys" placeholder="חיפה, תל-אביב" class="required" title="אנא הזן מיקום השיעורים‫.‬"/> 
    </div> 

    <div class="field"> 
    <label>מחיר לשיעור</label> 
    <input type="text" name="price" id="price" placeholder="100" class="required numeric min-length_2 max-length_4" title="המחיר צריך להכיל שתיים או שלוש ספרות‫.‬" /> 
    </div> 

    <div class="field"> 
    <label>תקציר מידע</label> 
    <textarea rows="8" cols="23" name="excerpt" id="excerpt" placeholder="שנות נסיון‫,‬ סגנון וכדומה‫...‬" class="required min-length_60 max-length_110" title="התקציר צריך להכיל בין 60 ל‫-‬110 מילים‫.‬"> 
    </textarea> 
    </div> 

    <div class="field"> 
    <label>תוכן העמוד</label> 
    <textarea rows="18" cols="50" name="inputcontent" id="inputcontent" placeholder="על אופי השיעורים‫,‬ מיקום השיעורים‫,‬ עוד עליכם וכדומה‫...‬" class="required min-length_300 max-length_1500" title="התוכן צריך להכיל לפחות 300 אותיות‫.‬"> 
    </textarea><br/> 
    ‪<‬span class="movieMessege"‪>‬ 
    *אפשר לצרף גם כתובת סרטון YouTube לתיבת התוכן והסרט יופיע בתוך העמוד. 
    </span> 
    </div> 

    <br/> 
    <div class="field"> 
    <label>תמונה אישית</label> 
    <input type="file" id="fileupload" accept="image/jpeg,image/jpg,image/bmp,image/png,/image/gif" class="required" title="אנא הזן תמונה ‫(‬תמונתך ולא פלייר או כדומה‫).‬"/> 
    </div> 

    <button name="send" class="btn" value="בחר קובץ">פרסם!</button><br/><br/><br/> 

    </form> 


    <div id="clear"></div> 

    <?php get_footer(); ?> 

這是我的PHP郵件:

<?php 

$SendFrom = "[email protected]"; 
$SendTo =  "[email protected]"; 
$SubjectLine = "מורה גיטרה חדש"; 
$ThanksURL = "http://www.guitara.co.il/%D7%94%D7%98%D7%95%D7%A4%D7%A1-%D7%A0%D7%A9%D7%9C%D7%97-%D7%91%D7%94%D7%A6%D7%9C%D7%97%D7%94/"; 

// Build Message Body from Web Form Input 
foreach ($_POST as $Field=>$Value) 
    $MsgBody .= "$Field: $Value\n"; 

$MsgBody = htmlspecialchars($MsgBody, ENT_NOQUOTES); //make safe 

// Send E-Mail and Direct Browser to Confirmation Page 
mail($SendTo, $SubjectLine, $MsgBody, "From: $SendFrom"); 
header("Location: $ThanksURL"); 

?> 

,我會很高興,如果一個能幫助我添加對PHP的郵件所需 代碼將文件附加到他正在發送的郵件。

ThankYouAnyWay !!!

回答

1
function XMail($from, $to, $subj, $text, $filename) { 
    $f   = fopen($filename,"rb"); 
    $un  = strtoupper(uniqid(time())); 
    $head  = "From: $from\n"; 
    $head  .= "To: $to\n"; 
    $head  .= "Subject: $subj\n"; 
    $head  .= "X-Mailer: PHPMail Tool\n"; 
    $head  .= "Reply-To: $from\n"; 
    $head  .= "Mime-Version: 1.0\n"; 
    $head  .= "Content-Type:multipart/mixed;"; 
    $head  .= "boundary=\"----------".$un."\"\n\n"; 
    $zag  = "------------".$un."\nContent-Type:text/html;\n"; 
    $zag  .= "Content-Transfer-Encoding: 8bit\n\n$text\n\n"; 
    $zag  .= "------------".$un."\n"; 
    $zag  .= "Content-Type: application/octet-stream;"; 
    $zag  .= "name=\"".basename($filename)."\"\n"; 
    $zag  .= "Content-Transfer-Encoding:base64\n"; 
    $zag  .= "Content-Disposition:attachment;"; 
    $zag  .= "filename=\"".basename($filename)."\"\n\n"; 
    $zag  .= chunk_split(base64_encode(fread($f,filesize($filename))))."\n"; 

    return @mail("$to", "$subj", $zag, $head); 

也期待在http://swiftmailer.org/

+0

感謝的,但我不知道如何利用它與我的工作代碼...?! – Ben 2011-06-05 11:09:21

+0

只需複製粘貼此功能即可。語法錯誤 - 最後缺少括號。然後用適當的參數調用這個函數。這很容易。文件名是完整的路徑在您的服務器文件 – zim32 2011-06-06 19:45:10

+0

我真的不怎麼樣,我只是複製和粘貼東西,直到它的工作,我真的不明白什麼是寫在那裏... – Ben 2011-06-07 07:54:37