Php 缩短存储在变量中的可单击url

Php 缩短存储在变量中的可单击url,php,Php,这是我当前的代码: $parcels = $api->parcels->get(); $url = (array_values($parcels)[0]['label']['label_printer']); $goToUrl = $api->getUrl($url); $goToUrl = str_replace('/api/v2//api/v2/', '/api/v2/', $goToUrl); print_r($goToUrl); echo "<br />

这是我当前的代码:

$parcels = $api->parcels->get(); 

$url = (array_values($parcels)[0]['label']['label_printer']);
$goToUrl = $api->getUrl($url);

$goToUrl = str_replace('/api/v2//api/v2/', '/api/v2/', $goToUrl);
print_r($goToUrl);
echo "<br />";
echo $url;
在电子邮件中使用的代码:

$email_body = ("This is Label: " . ($parcel_name) . " |OrderId: " . ($parcel_order_number) . "\n\n See Label: " . $goToUrl );
当前情况此url已通过电子邮件发送,在邮件中,我希望它是一个可单击的链接,而不是整个url。即使只有最后一部分也足够好:

label/label_printer/1369315

我见过preg\u replace,但以前从未使用过,所以我觉得很难理解它。

要在phpmailer中启用HTML,必须使用

$mailer->isHtml(true); //Enables html in the regular body.


您可以查看有关如何将phpmailer与html一起使用的示例/指南/正确配置它

要在phpmailer中启用HTML,必须使用

$mailer->isHtml(true); //Enables html in the regular body.


您可以查看有关如何将phpmailer与html一起使用的示例/指南/正确配置它

嗯,什么?缩短URL将导致其失败/缺少URL的部分?我不确定我是否理解,为什么不将其包装在
?@Epodax中?是的,url应该保持完整,正确的情况是您所描述的,但它在phpmailer中使用变量。我看不到使用html的机会?
$mailer->isHtml(true)
启用HTML或
$mailer->MsgHTML($body)
@Epodax您的评论帮助我获得了答案,因此将html设置为true是问题的起因,因为我的html不起作用。你能把它作为答案贴出来吗?那我就可以接受了什么?缩短URL将导致其失败/缺少URL的部分?我不确定我是否理解,为什么不将其包装在
?@Epodax中?是的,url应该保持完整,正确的情况是您所描述的,但它在phpmailer中使用变量。我看不到使用html的机会?
$mailer->isHtml(true)
启用HTML或
$mailer->MsgHTML($body)
@Epodax您的评论帮助我获得了答案,因此将html设置为true是问题的起因,因为我的html不起作用。你能把它作为答案贴出来吗?那我就可以接受了。
$mailer->MsgHTML($body); //Enables and SETS the message body with HTML.