在发送邮件上传文件的下载链接 [英] Send the download link of the uploaded file in a mail

查看:149
本文介绍了在发送邮件上传文件的下载链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在用的是的jQuery文件上传插件在我的网站。 该插件给我一个功能来下载该文件后上传它,这里的code

I am using the "jquery file upload plugin" in my website. The plugin give me a feature to download the file after uploaded it, and here's the code

<td class="download">
                <a href="{%=file.url%}" class="btn modal-download" title="{%=file.name%}" rel="{%=file.thumbnail_url&&'gallery'%}" download="{%=file.name%}">
                <i class="icon-download"></i>
                Download</a>
            </td>

现在,我需要让用户可以上传文件的下载网址发送电子邮件,所以我用的花哨的联系表格通过每个上传的文件发送电子邮件,而这里的code

Now, I need to make user can send email with the downloaded url of the uploaded file, so I used a fancy contact form to send email by each uploaded file, and here's the code

<td class="mail">
                <div id="form-container">
    <h1>Fancy Contact Form</h1>
    <h2>Drop us a line and we will get back to you</h2>

    <form id="contact-form" name="contact-form" method="post" action="fancymail/submit.php">
      <table width="100%" border="0" cellspacing="0" cellpadding="5">
        <tr>
          <td width="15%"><label for="name">Name</label></td>
          <td width="70%"><input type="text" class="validate[required,custom[onlyLetter]]" name="name" id="name" value="<?=$_SESSION['post']['name']?>" /></td>
          <td width="15%" id="errOffset">&nbsp;</td>
        </tr>
        <tr>
          <td><label for="email">Email</label></td>
          <td><input type="text" class="validate[required,custom[email]]" name="email" id="email" value="<?=$_SESSION['post']['email']?>" /></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td><label for="subject">Subject</label></td>
          <td width="70%"><input type="text" class="validate[required,custom[onlyLetter]]" name="subject" id="subject" value="<?=$_SESSION['post']['subject']?>" /></td>
          <!--<td><select name="subject" id="subject">
            <option value="" selected="selected"> - Choose -</option>
            <option value="Question">Question</option>
            <option value="Business proposal">Business proposal</option>
            <option value="Advertisement">Advertising</option>
            <option value="Complaint">Complaint</option>
          </select>          </td>-->
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td valign="top"><label for="message">Message</label></td>
          <td><textarea name="message" id="message" class="validate[required]" cols="35" rows="5"><?=$_SESSION['post']['message'] ?></textarea></td>
          <!--efoula-->

          <!--efoula-->
          <td valign="top">&nbsp;</td>
        </tr>
        <tr>
          <td><label for="captcha"><?=$_SESSION['n1']?> + <?=$_SESSION['n2']?> =</label></td>
          <td><input type="text" class="validate[required,custom[onlyNumber]]" name="captcha" id="captcha" /></td>
          <td valign="top">&nbsp;</td>
        </tr>
        <tr>
          <td valign="top">&nbsp;</td>
          <td colspan="2"><input type="submit" name="button" id="button" value="Submit" />
          <input type="reset" name="button2" id="button2" value="Reset" />

          <?=$str?>          <img id="loading" src="img/ajax-load.gif" width="16" height="16" alt="loading" /></td>
        </tr>
      </table>
      </form>
      <?=$success?>
    </div>
            </td>

此外使用submit.php文件来发送邮件,并在这里看中的联系方式是在code

Also the fancy contact form using a submit.php file to send the mail, and here's the code

<?php

/* config start */

$emailAddress = 'email@example.com';

/* config end */
$url = "http://domain.com/files=" .$file_name ;


require "phpmailer/class.phpmailer.php";
require "../server/php/upload.class.php";

session_name("fancyform");
session_start();


foreach($_POST as $k=>$v)
{
    if(ini_get('magic_quotes_gpc'))
    $_POST[$k]=stripslashes($_POST[$k]);

    $_POST[$k]=htmlspecialchars(strip_tags($_POST[$k]));
}


$err = array();

if(!checkLen('name'))
    $err[]='The name field is too short or empty!';

if(!checkLen('email'))
    $err[]='The email field is too short or empty!';
else if(!checkEmail($_POST['email']))
    $err[]='Your email is not valid!';

if(!checkLen('subject'))
    $err[]='You have not selected a subject!';

if(!checkLen('message'))
    $err[]='The message field is too short or empty!';

if((int)$_POST['captcha'] != $_SESSION['expect'])
    $err[]='The captcha code is wrong!';


if(count($err))
{
    if($_POST['ajax'])
    {
        echo '-1';
    }

    else if($_SERVER['HTTP_REFERER'])
    {
        $_SESSION['errStr'] = implode('<br />',$err);
        $_SESSION['post']=$_POST;

        header('Location: '.$_SERVER['HTTP_REFERER']);
    }

    exit;
}


$msg=
'Name:  '.$_POST['name'].'<br />
Email:  '.$_POST['email'].'<br />
Download: '.$url.'<br />


Message:<br /><br />

'.nl2br($_POST['message']).'

';


$mail = new PHPMailer();
$mail->IsMail();

$mail->AddReplyTo($_POST['email'], $_POST['name']);
$mail->AddAddress($emailAddress);
$mail->SetFrom($_POST['email'], $_POST['name']);
$mail->Subject = "A new ".mb_strtolower($_POST['subject'])." from ".$_POST['name']." | contact form feedback";

$mail->MsgHTML($msg);

$mail->Send();


unset($_SESSION['post']);

if($_POST['ajax'])
{
    echo '1';
}
else
{
    $_SESSION['sent']=1;

    if($_SERVER['HTTP_REFERER'])
        header('Location: '.$_SERVER['HTTP_REFERER']);

    exit;
}

function checkLen($str,$len=2)
{
    return isset($_POST[$str]) && mb_strlen(strip_tags($_POST[$str]),"utf-8") > $len;
}

function checkEmail($str)
{
    return preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $str);
}

?>

我现在尝试后上传文件的下载URL的邮件消息中, 我试图将其添加到:,我设置;,但是当我收到($味精=下载'$网址。)($ URL =http://domain.com/files=$ FILE_NAME)。邮件我刚刚收到。(下载地址:/文件=没有文件名)

Am trying now to post the download url of the uploaded file in the message of the mail, I tried to add it in ($msg= Download: '.$url.'), and I set the ($url = "http://domain.com/files=" .$file_name ; ), but when I received the mail I just received (Download: /file= "without the file name").

我要张贴在邮件中上传文件的完整URL。 任何帮助???

I need to post the full url of the uploaded file in the mail. Any Help???

推荐答案

在submit.php $ URL =htt​​p://domain.com/files=$ FILE_NAME;

in submit.php $url = "http://domain.com/files=" .$file_name ;

$ FILE_NAME 未定义;你需要发布此数据从形式以及

$file_name is undefined; you need to post this data from your form as well

假设&LT; TD类=下载&GT; 是在你的形式在同一页面中的&LT; TD类=邮件&GT;

Assuming that <td class="download"> is in the same page of your form in <td class="mail">

添加你想要在你的形式使用与隐藏的输入值

add the value you want to use in your form with an hidden input

 <input type="hidden" name="url" value="{%=file.url%}" />

在submit.php变化

in submit.php change

下载:$网址。&LT; BR /&GT;

下载:[URL']。'&LT; BR /&GT;

你的问题是,在你的表单,你不要张贴相关的 {%= file.url%​​} 数据。

your problem is that in your form you don't post the related {%=file.url%} data.

$ EMAILADDRESS分配字符串'email@example.com 覆盖$ EMAILADDRESS与$ _ POST [电子邮件]的值。 (在这个例子中我覆盖$网址的价值,创造一个变量$ usrname并为它们分配的$ _ POST当量)

$emailAddress is assigned the string 'email@example.com' overwrite the value of $emailAddress with $_POST['email']. (in this example i overwrite the value of $url and create a variable $usrname and assign them the $_POST equivalent )

替换

$msg=
'Name:  '.$_POST['name'].'<br />
Email:  '.$_POST['email'].'<br />
Download: '.$url.'<br />


Message:<br /><br />

'.nl2br($_POST['message']).'

';

通过这种

$usrname = $_POST['name'];
$emailAddress = $_POST['email'];
$url = $_POST['url'];

$msg=
'Name:  '.$usrname.'<br />
Email:  '.$emailAddress.'<br />
Download: '.$url.'<br />


Message:<br /><br />

'.nl2br($_POST['message']).'

';

这篇关于在发送邮件上传文件的下载链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆