Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php邮件中的html链接_Php_Html_Email_Plaintext - Fatal编程技术网

php邮件中的html链接

php邮件中的html链接,php,html,email,plaintext,Php,Html,Email,Plaintext,我有以下代码向用户发送电子邮件 $mes_body.="Click to Login. www.website.com/index.php\n\n"; $mes_body.= "<a href='www.website.com/index.php'>Click to Login.</a>\n\n"; $mes_body.=“单击登录www.website.com/index.php\n\n”; $mes\u body.=“\n\n”; 现在我看到的电子邮件是: C

我有以下代码向用户发送电子邮件

$mes_body.="Click to Login. www.website.com/index.php\n\n";  
$mes_body.= "<a href='www.website.com/index.php'>Click to Login.</a>\n\n";
$mes_body.=“单击登录www.website.com/index.php\n\n”;
$mes\u body.=“\n\n”;
现在我看到的电子邮件是:

Click to Login. www.website.com/index.php

<a href='www.website.com/index.php'>Click to Login.</a>
单击以登录。www.website.com/index.php

我们想要的是一个可点击的“点击登录”,而不是确切的链接。我想我用的是普通测试。我现在无法更改它,因此是否有任何解决方法?谢谢。

您需要发送一封HTML电子邮件

有关如何做到这一点的简单示例,请参见中的示例4

但是,为了最大限度地兼容,您还应该始终发送文本替代方案。要发送多部分电子邮件,最方便的方法是使用现有的邮件库,如。

参见示例4“发送HTML电子邮件”


问题是您的邮件需要MIME标题将其标记为HTML而不是纯文本。

如果没有HTML,则无法使用HTML格式

(显然)

您需要切换到HTML电子邮件或删除HTML标记


请注意,大多数电子邮件客户端将自动使明文消息中的URL可单击。

否。在明文电子邮件中,最接近超链接的URL是客户端检测到并使其可单击的URI。除了URI本身,绝对没有办法使文本成为任何其他内容


如果你想这样做,那么你需要使用HTML格式化你的电子邮件(并且应该使它成为一封包含合理的纯文本替代内容的多部分电子邮件)。

对不起,我不知道我的HTML将被格式化为链接,我希望这一次能起作用

只要确保在链接的开头包含('http://'),那么它在发送时就可以单击。

使用此示例代码

<?php
//mail customer
$from = 'donotreply@mysite.co.uk';
$to = "email@example.com"; //write the email here.
$subject = 'Title of Email';

$headers = "MIME-Version: 1.0\r\n"; 
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
$headers .= "From: Name of Company <$from>\r\n";

$msg = '
<html>
<head>
<link href="http://linktocss/.../etc" rel="stylesheet" type="text/css" />
</head>

<body>

<p>I am testing this message.</p>

<a href="https://www.w3schools.com/html/">Visit our HTML tutorial</a>

<div>
This is a clear test to go back to the line. 
</div>

Regards, <br>

Company Name.

</body>
</html>
';

mail($to, $subject, $msg, $headers) or die ("mail error");

?>

我之所以回答这个问题,是因为我今天遇到了同样的问题,而这个答案对我来说并不适用。如果有人有这个问题,我的回答可能会有所帮助