php 带附件的自定义表单

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 带附件的自定义表单相关的知识,希望对你有一定的参考价值。

<?php
    $diname = Mage::getModel('core/variable')->loadByCode('uploads_dir_name')->getValue('html');
    if($this->helper('customer')->isLoggedIn())
    {
        $first_name = Mage::helper('customer')->getCustomer()->getData('firstname');
        $last_name = Mage::helper('customer')->getCustomer()->getData('lastname');
        $user_email = Mage::helper('customer')->getCustomer()->getData('email');
    }
    if(isset($_REQUEST['submit-your-story']) && !empty($_REQUEST['submit-your-story']) && !empty($diname))
    {
        $storeId = Mage::app()->getStore()->getId();  
        $address = Mage::getStoreConfig('trans_email/ident_general/email', $storeId);
        $name = Mage::getStoreConfig('trans_email/ident_general/name', $storeId);
        
        $diname = Mage::getModel('core/variable')->loadByCode('uploads_dir_name')->getValue('html');
        
        $_emaiTemplateName = Mage::getModel('core/variable')->loadByCode('temaplte_submit_story')->getValue('html');
        $emailTemplate = Mage::getModel('core/email_template')->loadByCode($_emaiTemplateName);
        
        $emailTemplateVariables = array('story-firstname' => $_REQUEST['story-firstname'],
                                        'story-lastname' => $_REQUEST['story-lastname'],
                                        'story-email' => $_REQUEST['story-email'],
                                        'story-title' => $_REQUEST['story-title'],
                                        'story-phone' => $_REQUEST['story-phone'],
                                        'story' => $_REQUEST['story']);
        $files = $_FILES;

        $path = BP . DS . 'media/'. $diname .'/';
        if(!is_dir($path))
        {
            mkdir($path, 0777, true);
        }
        
        foreach($files as $file)
        {
            if(!empty($file['tmp_name']))
            {
                move_uploaded_file($file['tmp_name'], $path.$file["name"]);
                $fileContents = file_get_contents($path.$file["name"]);
                $attachment = $emailTemplate->getMail()->createAttachment($fileContents);
                $attachment->type = $file["type"];
                $attachment->filename = $file["name"];
            }
        }
        
        $emailTemplate->getProcessedTemplate($emailTemplateVariables);
        $emailTemplate->setSenderEmail(Mage::getStoreConfig('trans_email/ident_general/email', $storeId));
        $emailTemplate->setSenderName(Mage::getStoreConfig('trans_email/ident_general/name', $storeId));
        $emailTemplate->send($address, $name, $emailTemplateVariables);
    }
?>

<div class="lightbox" id="lightbox-submit">
    <a href="#" class="close"><?php echo $this->__('close'); ?></a>
    <h1><span><?php echo $this->__('submit'); ?></span> <?php echo $this->__('your story'); ?></h1>
    <form action="" name="submit-your-story-form" enctype="multipart/form-data" method="post">
        <fieldset>
            <input type="hidden" name="submit-your-story" value="1" />
            <div class="row">
                <div class="field field-col">
                    <label for="story-firstname"><?php echo $this->__('first name'); ?> <em>*</em></label>
                    <div class="input-text">
                        <input type="text" id="story-firstname" name="story-firstname" value="<?php echo $first_name; ?>" placeholder="<?php echo $first_name; ?>" />
                    </div>
                </div>
                <div class="field field-col field-col-alt">
                    <label for="story-lastname"><?php echo $this->__('Last name'); ?> <em>*</em></label>
                    <div class="input-text">
                        <input type="text" id="story-lastname" name="story-lastname" value="<?php echo $last_name; ?>" placeholder="<?php echo $last_name; ?>" />
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="field">
                    <label for="story-email"><?php echo $this->__('email address'); ?> <em>*</em></label>
                    <div class="input-text">
                        <input type="email" name="story-email" value="<?php echo $user_email; ?>" placeholder="<?php echo $user_email; ?>" id="story-email" />
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="field">
                    <label for="story-title"><?php echo $this->__('Story title'); ?> <em>*</em></label>
                    <div class="input-text">
                        <input type="text" id="story-title" name="story-title" />
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="field">
                    <label for="story-phone"><?php echo $this->__('Phone Number'); ?> <em>*</em></label>
                    <div class="input-text">
                        <input type="tel" id="story-phone" name="story-phone" />
                    </div>
                </div>
            </div>
            <div class="row">
                <label for="story"><?php echo $this->__('your Story'); ?> <em>*</em></label>
                <textarea id="story" cols="30" rows="10" name="story"></textarea>
                <span class="note"><?php echo $this->__('500 Characters Remaining'); ?></span>
            </div>
            <div class="row row-file">
                <label for="story-image1"><?php echo $this->__('image 1'); ?> <em>*</em></label>
                <input id="story-image1" type="file" name="image1" />
            </div>
            <div class="row row-file">
                <label for="story-image2"><?php echo $this->__('image 2'); ?></label>
                <input id="story-image2" name="image2" type="file" />
            </div>
            <div class="row row-file">
                <label for="story-image3"><?php echo $this->__('image 3'); ?></label>
                <input id="story-image3" name="image3" type="file" />
            </div>
            <p class="required"><em>*</em> <?php echo $this->__('Required fields'); ?></p>
            <div class="row-btn">
                <input type="submit" value="<?php echo $this->__('Submit story'); ?>" />
            </div>
        </fieldset>
    </form>
</div>

First Name :  {{var story-firstname}}
Last Name : {{var story-lastname}}
Email  : {{var story-email}}
Title : {{var story-title}}
Phone : {{var story-phone}}
Story : 
{{var story}}

<div class="lightbox lightbox-preview" id="deedpreview">
        <header>
            <img src="{{var logo_url}}" width="224" height="60" alt="deed carrier" class="logo-alt" />
            <h2>your good deeds delivered</h2>
        </header>
        <div class="letter">
            <div class="letter-block">
                <div class="letter-block-holder">
                    <h2>Dear Friend,</h2>
                    <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr,  sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores.</p>
                    <em>Sincerly, Isadora </em>
                    <div class="visual"><img src="{{skin url="images/img06.png" _area='frontend' _package="default" _theme="deedcarrier"}}" width="129" height="181" alt="image descritpion" /></div>
                </div>
            </div>
            <footer>
                <p>DeedCarrier is the courier service for ones<br/> compassionate, giving, and caring nature.  In only 3 easy steps, we take good in the form of the deed you want to do, package it, and send it to that special person in your life.  You can create your own specific good deed, or find inspiration from our list of deeds. </p>
                <a href="#">DeedCarrier.com</a>
            </footer>
        </div>
    </div>

.letter .letter-block {
    border:1px solid #eee;
    padding:13px;
    font:16px/26px Verdana, Geneva, Arial, Helvetica, sans-serif;
    color:#666;
}
.letter .letter-block h2 {
    font:17px/26px Verdana, Geneva, Arial, Helvetica, sans-serif;
    color:#666;
    margin:0 0 18px;
}
.letter .letter-block p {margin:0 0 23px;}
.letter-block-holder {
    background:#f7f7f7;
    padding:33px 40px;
    border:1px dashed #c9c9c9;
}
.letter-alt .letter-block-holder {padding:33px 40px 146px;}
.letter-block-summer {background:#f7f7f7 url(../images/bg-box03.png) no-repeat 50% 100%;}
.letter .visual {padding:10px 0 0;}
.letter .visual img {
    display:block;
    margin:0 auto;
}
.letter footer {
    width:350px;
    height:184px;
    font:12px/15px Times, Georgia, serif;
    color:#999;
    padding:296px 160px 0;
    margin:-214px -17px 0;
    position:relative;
    text-align:center;
    background:url({{skin url="images/bg-bottom-spring.png" _area='frontend' _package="default" _theme="deedcarrier"}}) no-repeat;
}
.letter-alt footer {margin:-247px -17px 0;}
.letter footer p {
    position:relative;
    padding:0 0 22px;
}
.letter footer p:after {
    width:90px;
    height:1px;
    position:absolute;
    bottom:0;
    left:50%;
    margin-left:-45px;
    content:'';
    background:#999;
}
.letter footer a {
    text-decoration:none;
    color:#df5964;
}
.letter footer a:hover {text-decoration:underline;}
.lightbox {
    width:552px;
    margin:0 auto;
    position:relative;
    border:13px solid #fff;
    background:#f7f7f7;
    padding:22px 28px 26px;
}
.lightbox:before {
    position:absolute;
    top:0;
    left:0;
    right:0;
    bottom:0;
    content:'';
    border:1px dashed #c9c9c9;
}
.lightbox h1 {
    text-align:center;
    margin:0 0 36px;
    padding:0 0 17px;
    position:relative;
    font:3.214em/1.2em 'playfair_displaybold', Times, serif;
    text-transform:uppercase;
    color:#7d7d7d;
    letter-spacing:1px;
}
.lightbox h1:after {
    width:202px;
    height:2px;
    background:#de5158;
    position:absolute;
    bottom:0;
    left:50%;
    margin-left:-101px;
    content:'';
}
.lightbox h1 span {color:#666;}
.lightbox .row {
    overflow:hidden;
    padding:0 0 32px;
    position:relative;
}
.lightbox .row-btn {margin-top:-5px;}
.lightbox .row-file {
    margin:0 0 24px;
    padding:0 0 1px;
}
.lightbox .row-file:after {
    width:405px;
    height:1px;
    position:absolute;
    bottom:0;
    content:'';
    background:#cbcbcb;
    left:0;
}
.lightbox .field {
    overflow:hidden;
    padding:0 0 1px;
    border-bottom:1px solid #cbcbcb;
}
.lightbox .field-col {
    float:left;
    width:45%;
    margin:0 10% 0 0;
}
.lightbox .field-col-alt {margin:0;}
.lightbox label {
    text-transform:uppercase;
    color:#666;
    float:left;
    padding:0 11px 5px 3px;
    font-size:12px;
    font-weight:700;
    line-height:16px;
}
.lightbox .row-file label {
    font-weight:normal;
    padding:5px 10px 5px 3px;
}
.lightbox .required {
    margin:0;
    color:#7d7d7d;
    text-align:right;
}
.lightbox label em,
.lightbox .required em {
    font-style:normal;
    color:#de5158;
}
.lightbox-preview {
    padding:32px 70px 64px 60px;
    width:636px;
    background:#fff;
    border:0;
}
.lightbox-preview:before {display:none;}
.lightbox-preview .close {
    top:19px;
    right:24px;
}
.lightbox-preview header {
    padding:0 0 30px;
    width:100%;
}
.lightbox-preview header:after{
    display:block;
    clear:both;
    content:'';
}
.lightbox-preview header h2 {
    text-transform:uppercase;
    float:right;
    color:#7d7d7d;
    margin:37px 12px 0 0;
    font:14px/20px 'playfair_displaybold',Times,serif;
}
.lightbox-preview .logo-alt {
    float:left;
    width:205px;
    height:auto;
    margin-left:-4px;
}

以上是关于php 带附件的自定义表单的主要内容,如果未能解决你的问题,请参考以下文章

php 获取带分类的自定义帖子

jquery 发送带附件的邮件

如何在 UITableViewCell 中获得透明的附件视图? (带截图)

更改 uitableviewcell 中的自定义附件视图?

PHP 项目对接视频号原来如此简单,小白也能轻松完成带附件

在 PHP 中将 CSV 写入不带附件的文件