MIME 1.0 URL包含%0D%20

时间:2019-02-14 16:48:46

标签: php mime-types mime

我有一个PHP脚本,可以在提交后通过电子邮件向用户发送电子邮件,但是我遇到了一个问题,即消息中的嵌入式链接在URL本身内包含%0D%20。

我无法弄清楚如何消除此问题,因为当您单击链接时,这显然不是链接。

显示的URL是正确的,没有%0D%20,但是,当您将鼠标悬停在标签上时,我会看到此信息。

当您单击链接时,链接将显示为:

https://URL/public/dermatology/2019/client_generatePDF.p%0D hp?id=21%08 8&pid=Horus 

在扩展名php中间现在有一个%0D,在数据库ID中间有一个%08,它来自$ last_id,即插入到数据库中的记录的ID。

我也尝试过href ='“。$ url_pdf。”'

这是脚本的链接部分。

$message .= "<tr><td colspan='2'>Link to full history: <a href='$url_pdf' target='_blank'>" . $url_pdf ." </a></td></tr>";




$last_id = $stmt->insert_id;
    $PetName2 = trim($_POST['Pet_Name']);

    $url = "https://URL/public/dermatology/2019/client_upload_form.php?id=". $last_id . "&pid=" . $PetName2 ;
    $url_pdf = "https://URL/public/dermatology/2019/client_generatePDF.php?id=". $last_id . "&pid=" . $PetName2 ;

    $email = "SEND EMAIL";
    $to = "EMAIL, $ClientEmailAddress";
    $from = "VMC Dermatology Form Submission";
    $subject = "Dermatology Client Form Submission: " . $UMNCaseNo . "";

    $headers = "From: " . strip_tags($email) . "\r\n";  
    $headers .= "MIME-Version: 1.0 \r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1 \r\n";

    $message = '<html><body><h3>A Dermatology Consultation Has Been Submitted.</h3><br />';
    $message .= "<br />";
    $message .= "<br />";
    $message .= "Thank you&nbsp; " . $Client_First_Name ." &nbsp; for filling out the Dermatology Questionnaire for your pet " .$Pet_Name . ".&nbsp;Your information has been received. If applicable, you may submit photos regarding your pets skin condition using the following link. <a href='" .$url. "' > ". $url ."</a>";
    $message .= "<br />";
    $message .= "<br />";
    $message .= "<table rules='all' style='border-color: #666;' cellpadding='10'>";
    $message .= "<tr style='background: #eee;'>  <td width='178px'><strong>Today's Date:</strong> </td>  
                  <td width='380px'>" . $date2 . "</td></tr>";
    $message .= "<tr> <td><strong>Case Number:</strong></td>  <td>" . $UMNCaseNo . "</td></tr>";
    $message .= "<tr> <td><strong>Clinic to Be Seen at:</strong></td>  <td>" . $ClinicToBeSeenAt . "</td></tr>";
    $message .= "<tr><td colspan='2'>&nbsp;</td></tr>";
    $message .= "<tr> <td><strong>Client Name:</strong> </td><td>" . $Client_First_Name . " ". $Client_Last_Name ."</td></tr>";
    $message .= "<tr><td><strong>Client Phone Number:</strong></td> <td>" . $Phone . "</td></tr>";
    $message .= "<tr><td><strong>Client Email:</strong></td> <td>" . $ClientEmailAddress . "</td></tr>";
    $message .= "<tr><td colspan='2'>&nbsp;</td></tr>";

    $message .= "<tr><td colspan='2'>&nbsp;</td></tr>";
    $message .= "<tr><td><strong>Pet Name:</strong></td> <td>" . $Pet_Name . "</td></tr>";  
    $message .= "<tr><td><strong>Species:</strong></td> <td>" . $Species . "</td></tr>";    
    $message .= "<tr><td><strong>Breed:</strong></td> <td>" . $Breed . "</td></tr>";
    $message .= "<tr><td colspan='2'>&nbsp;</td></tr>";
    $message .= "<tr style='background: #eee'><td colspan='2'><strong>Reason for Visit:</strong></td></tr>";
    $message .= "<tr><td colspan='2'>" . $Reason_for_Visit . "</td></tr>";
    $message .= "<tr><td colspan='2'>&nbsp;</td></tr>";
    $message .= "<tr><td colspan='2'>Link to full history: <a href='$url_pdf' target='_blank'>" . $url_pdf ." </a></td></tr>";
    $message .= "<tr><td colspan='2'>&nbsp;</td></tr>";
    $message .= "</table>";
    $message .= "</body></html>";
    $message .= "<br />";

if(mail($to,$subject,$message,$headers)){

1 个答案:

答案 0 :(得分:0)

%0D%20是URL编码的换行符,后跟一个空格。浏览器将显示该版本的解码版本,这就是为什么您仅在过渡时看到它的原因。过滤文件名中的字符,例如:

$url_pdf = preg_replace('/[ \n\r\t]/', '', $url_pdf);

您当然需要确保使用此过滤后的名称保存文件,否则下载将中断。

我还建议您使用PHPMailer,因为您已用问题标记了这个问题。