使用php共享文件

时间:2016-12-08 05:55:28

标签: php email session

我的问题是无法向邮件发送可下载的链接, 实际上我选择了两个变量,我已经获得了(userID,userPic)的值,所以现在我无法将链接发送到邮件

 <?php
    if(isset($_POST['useremail'])) {


    $uploadID =  $_GET['uploadID'];
    $filename =    $_GET['userPic'];
    $memberID =$_SESSION['memberID'];
    $email   =     $_SESSION['email'];
    $mail  =     $_POST['useremail'];

    $stmt = $DB_con->prepare('INSERT INTO share(uploadID,useremail,userPic,memberID) VALUES(:uploadID, :useremail,:userPic, :memberID)');
                $stmt->bindParam(':uploadID',$uploadID);
                $stmt->bindParam(':useremail',$mail);
                $stmt->bindParam(':userPic',$filename);
                $stmt->bindParam(':memberID',$memberID);

                if($stmt->execute())
                {
                    $successMSG = "succesfully sended mail ..." ;
                    header("location:user.php"); 
                }   


    > Blockquote
    $url = "<p>

 <a href='http://www.adroitsws.com/data_transfer/download.php?filename=<?php echo $row['userPic']; ?>'>http://www.adroitsws.com/data_transfer/download.php?filename=<?php echo $row['userPic']; ?></a></p>"

     $email_from =$email;

        $email_subject = "Your email subject line";

        function died($error) {

            // your error code can go here

            echo "We are very sorry, but there were error(s) found with the form you submitted. ";

            echo "These errors appear below.<br /><br />";

            echo $error."<br /><br />";

            echo "Please go back and fix these errors.<br /><br />";

            die();

        }
            if(!isset($_POST['useremail'])  ) {   

            died('We are sorry, but there appears to be a problem with the form you submitted.');       

        }

        $email_to = $_POST['useremail']; // required

        $error_message = "";

        $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

      if(!preg_match($email_exp,$email_to)) {

        $error_message .= 'The Email Address you entered does not appear to be valid.<br />';

      }


        function clean_string($string) {

          $bad = array("content-type","bcc:","to:","cc:","href");

          return str_replace($bad,"",$string);

        }

        $email_message .= "mail: ".clean_string($email_to)."\n";

    // create email headers

    $headers = 'From: '.$email_from."\r\n".

    'Reply-To: '.$email_to."\r\n" .

    'X-Mailer: PHP/' . phpversion();

    @mail( $email_to, $email_subject,$url, $email_message, $headers);  

    ?>

1 个答案:

答案 0 :(得分:1)

您可以查看以下链接,其中显示了如何在php中发送带附件的邮件。

  1. From stackoverflow
  2. From sanwebe
  3. From tutdepot
  4. 另请注意,在您的代码中存在错误。请通过以下代码替换您的$ URL并检查。

    $url = "<p> <a href=http://www.adroitsws.com/data_transfer/download.php?filename=".$row['userPic'].">"
                . "http://www.adroitsws.com/data_transfer/download.php?filename=".$row['userPic']."</a></p>";