0

我在我的网站中使用“ jquery 文件上传插件”。该插件为我提供了上传文件后下载文件的功能,这是代码

<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>

现在,我需要让用户可以使用下载的上传文件的 url 发送电子邮件,所以我使用了一个花哨的联系表格来发送每个上传文件的电子邮件,这里是代码

<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 文件发送邮件的精美联系表格,这里是代码

<?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,我尝试将其添加到 ($msg= Download: '.$url.') 中,并设置 ($url = "http: //domain.com/files=" .$file_name ; ),但是当我收到我刚刚收到的邮件时(下载:/file="没有文件名")。

我需要在邮件中发布上传文件的完整 url。任何帮助???

4

2 回答 2

1

在提交.php$url = "http://exemple.com/files=" .$file_name ;

$file_name未定义;_ 您还需要从表单中发布此数据。

答案第 1 部分:File.URL 未传递,或显示给用户

假设它<td class="download">在您表单的同一页面中<td class="mail">

使用隐藏输入添加要在表单中使用的值

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

在 submit.php 更改

Download: '.$url.'<br />

为了

Download: '.$_POST['url'].'<br />

您的问题是在您的表单中您没有发布相关{%=file.url%}数据。

回答第 2 部分:$emailAddress = 'email@example.com';

$emailAddress 被分配了字符串'email@example.com' 用$_POST['email'] 覆盖$emailAddress 的值。(在此示例中,我覆盖了 $url 的值并创建了一个变量 $usrname 并为它们分配了 $_POST 等效项)

代替

$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']).'

';
于 2012-10-13T08:38:24.220 回答
0

最好检查您使用的变量是否存在,例如:

$url = isset($file_name) ? 'http://domain.com/files=' .$file_name : 'http://domain.com/files=no_img';

如果您在 URL 中获得“no_img”,则该变量$file_name不存在。也许它是在另一个 php 文件中定义的,您应该将它包含在该脚本中。

于 2012-10-13T08:28:55.973 回答