简体   繁体   中英

creating a html mailto with php

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)

I have the body of the message saved under a variable $body and the email address saved under $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

echo "<a href='mailto:" . $to . "?body=" . $body . "'>";

$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.

Try with this:

<a href="mailto:<?php echo $to; ?>?body=<?php echo $body; ?>"><?php echo $to; ?></a>

Will generate

<a href="mailto:youremail@mail.com?body=This is the body of the message">youremail@mail.com</a>

您正在寻找的是(我在php标记中放置了所有空格,以供该编辑器使用我的所有字符而不解释它们):

< a href="mailto:< ? php echo $to; ? >?subject=< ? php echo $subject; ? >&cc=< ? php echo $cc; ? >&body=< ? php echo $body;? > " >
<a href='mailto:'<?php echo $to ?>'><?php echo $body ?></a>

try this:

<?php

echo "<a href='mailto:{$to}?body={$body}'>";

?>

基本上,您需要这样的东西:

<a href="mailto:$to?subject=$subject&body=$body&cc=$cc">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM