2011-06-04 116 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