【问题标题】:I need some help with php mailer (attaching a file)我需要一些关于 php mailer 的帮助(附加文件)
【发布时间】:2011-06-04 20:44:39
【问题描述】:

我有一个我喜欢的工作 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="israel@israeli.com" 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 =    "bentalgad@gmail.com";
$SendTo =      "bentalgad@gmail.com";
$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!!!

【问题讨论】:

    标签: php webforms sendmail actionmailer


    【解决方案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/

    【讨论】:

    • 谢谢,但我不知道如何在我的工作代码中使用它...?!
    • 复制粘贴此功能即可。有语法错误 - 最后缺少括号。然后只需使用适当的参数调用此函数。这很容易。文件名是服务器中文件的完整路径
    • 我真的不知道,我只是复制和粘贴东西直到它起作用,我真的不明白那里写的任何东西......
    猜你喜欢
    • 2014-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-01
    • 1970-01-01
    • 2011-08-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多