Reputation: 113
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
Upvotes: 1
Views: 60426
Reputation: 11
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):
< a href="mailto:< ? php echo $to; ? >?subject=< ? php echo $subject; ? >&cc=< ? php echo $cc; ? >&body=< ? php echo $body;? > " >
Upvotes: 1
Reputation: 360762
$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.
Upvotes: 6
Reputation: 5200
<a href='mailto:'<?php echo $to ?>'><?php echo $body ?></a>
Upvotes: 0
Reputation: 1357
Basically you want something that looks like this:
<a href="mailto:$to?subject=$subject&body=$body&cc=$cc">
Upvotes: -1
Reputation: 25445
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>
Upvotes: 4