MIME 1.0 URL包含%0D%20

问题描述 投票:0回答:1

我有一个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)){
php mime-types mime
1个回答
0
投票

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

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

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

我还建议使用PHPMailer,因为你用它标记了问题。

© www.soinside.com 2019 - 2024. All rights reserved.