Haw Haw
Haw Haw

Reputation: 113

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

Upvotes: 1

Views: 60426

Answers (7)

Adi
Adi

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

Ameer
Ameer

Reputation: 771

try this:

<?php

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

?>

Upvotes: 0

Marc B
Marc B

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

CamelCamelCamel
CamelCamelCamel

Reputation: 5200

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

Upvotes: 0

Andrew
Andrew

Reputation: 1357

Basically you want something that looks like this:

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

Upvotes: -1

barfoon
barfoon

Reputation: 28187

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

Upvotes: 12

Damien Pirsy
Damien Pirsy

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

Related Questions