php php邮件中的html链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3355211/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
html link in php mail
提问by Scorpion King
I have the following code to send an email to the users.
我有以下代码可以向用户发送电子邮件。
$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";
Right now i am seeing the email as :
现在我看到的电子邮件是:
Click to Login. www.website.com/index.php
<a href='www.website.com/index.php'>Click to Login.</a>
What is want is a clickable 'Click to Login' and not the link exactly. I guess i am using plaintest. i cant change it right now so is there any workaround for this? Thanks.
需要的是可点击的“点击登录”,而不是确切的链接。我想我正在使用plaintest。我现在无法更改它,所以有什么解决方法吗?谢谢。
回答by Borealid
See Example #4, "Sending HTML Email", on the PHP mail() documentation page.
请参阅PHP mail() 文档页面上的示例 #4,“发送 HTML 电子邮件” 。
The issue is that your message needs MIME headers marking it as HTML rather than plain text.
问题是您的消息需要 MIME 标头将其标记为 HTML 而不是纯文本。
回答by Quentin
No. The closest you can come to a hyperlink in plain textemail is a URI that the client detects and makes clickable. There is absolutely no way to make the text be anything other than the URI itself.
不可以。最接近纯文本电子邮件中的超链接的是客户端检测到并使其可点击的 URI。绝对没有办法让文本成为 URI 本身以外的任何东西。
If you want that, then you need to format your email using HTML (and should make it a multipart email which includes a sensible plain text alternative).
如果你想要这样,那么你需要使用 HTML 来格式化你的电子邮件(并且应该使它成为一个多部分的电子邮件,其中包含一个合理的纯文本替代方案)。
回答by Eathorne
sorry i didnt know my HTML will be formated to links i hope it works this time.
抱歉,我不知道我的 HTML 将被格式化为链接,我希望这次可以正常工作。
just make sure you include the ('http://') at the begining of the link, then it will become clickable when sent.
只需确保在链接的开头包含 ('http://'),然后在发送时它就会变得可点击。
回答by Julien Fadel
Use this sample code.
使用此示例代码。
<?php
//mail customer
$from = '[email protected]';
$to = "[email protected]"; //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");
?>
Hope this helps.
希望这可以帮助。
回答by Pekka
You need to send a HTML E-Mail.
您需要发送 HTML 电子邮件。
For a simple example on how to do that, see Example #4 in the PHP manual to mail().
有关如何执行此操作的简单示例,请参阅mail()的PHP 手册中的示例 #4 。
You should however always also send along a text alternative for maximum compatibility. To send multipart E-Mails, it's most convenient to use an existing mailing library like SwiftMailer.
但是,您还应该始终发送文本替代方案以获得最大的兼容性。要发送多部分电子邮件,最方便的是使用现有的邮件库,例如SwiftMailer。
回答by SLaks
It is not possible to use HTML formatting without HTML.
没有 HTML 就不可能使用 HTML 格式。
(Obviously)
(明显地)
You need to switch to HTML emails or drop the HTML tags.
您需要切换到 HTML 电子邮件或删除 HTML 标签。
Note that most email clients will automatically make URLs in plaintext messages clickable.
请注意,大多数电子邮件客户端会自动使纯文本消息中的 URL 可点击。

