用 php 创建一个 html mailto
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7665028/
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
creating a html mailto with php
提问by Haw Haw
cannot use the mail function in php, will be creating a mailto link in html instead. (the kind you click on and it pops up a window)
无法使用 php 中的邮件功能,将在 html 中创建一个 mailto 链接。(你点击的那种,它会弹出一个窗口)
I have the body of the message saved under a variable $body and the email address saved under $email
我将邮件正文保存在变量 $body 下,电子邮件地址保存在 $email 下
<?php
echo"
<a href="mailto: $to ?body= $body ">
";
?>
I know that code would not work, how do I put the email address and the body variables in there? thanks
我知道该代码不起作用,如何将电子邮件地址和正文变量放入其中?谢谢
回答by barfoon
echo "<a href='mailto:" . $to . "?body=" . $body . "'>";
echo "<a href='mailto:" . $to . "?body=" . $body . "'>";
回答by Marc B
$fixed_body = htmlspecialchars($body);
echo <<<EOL
<a href="mailto:$email?body=$fixed_body">Click here</a>
EOL;
htmlspecialchars will prevent any "
in the email body from "breaking" the <a>
tag. And the heredoc is just a nice little touch so you can use direct variable interpolation without having to escape the href attribute quotes.
htmlspecialchars 将防止"
电子邮件正文中的任何内容“破坏”<a>
标签。并且 heredoc 只是一个很好的小接触,因此您可以使用直接变量插值而不必转义 href 属性引号。
回答by Damien Pirsy
Try with this:
试试这个:
<a href="mailto:<?php echo $to; ?>?body=<?php echo $body; ?>"><?php echo $to; ?></a>
Will generate
会产生
<a href="mailto:[email protected]?body=This is the body of the message">[email protected]</a>
回答by Adi
What you're looking for is (I've put spaces all over php tags for this editor to take all my characters and not interpret them):
你要找的是(我已经在这个编辑器的 php 标签上加了空格来获取我所有的字符而不是解释它们):
< a href="mailto:< ? php echo $to; ? >?subject=< ? php echo $subject; ? >&cc=< ? php echo $cc; ? >&body=< ? php echo $body;? > " >
回答by CamelCamelCamel
<a href='mailto:'<?php echo $to ?>'><?php echo $body ?></a>
回答by Ameer
try this:
尝试这个:
<?php
echo "<a href='mailto:{$to}?body={$body}'>";
?>
回答by Andrew
Basically you want something that looks like this:
基本上你想要看起来像这样的东西:
<a href="mailto:$to?subject=$subject&body=$body&cc=$cc">
<a href="mailto:$to?subject=$subject&body=$body&cc=$cc">