Sam Williams
Sam Williams

Reputation: 177

Button Link inside php mail message

I am trying to send an automated email which has a button to download a report; the problem I have is that I can not seem to find away for the php link to show as a button or even a link, it just prints out the code.

My code is below; any suggestions would be appreciated. Thanks

$to = "$email";
$subject = "Alert Report";
$message = " 
<a href=\"http://www.mywebsite.com/test.php?id={$id}\" class='button'>Download Report</a> 
";
$from = "My Website";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers); 

Upvotes: 2

Views: 4814

Answers (3)

Vijay Verma
Vijay Verma

Reputation: 3698

You need to add some other header parameter:

$to = "$email";
$subject = "Alert Report";
$message = " 
<a href=\"http://www.mywebsite.com/test.php?id={$id}\" class='button'>Download Report</a> 
";
$headers  = "From: $from\r\n"; 
$headers  .= 'MIME-Version: 1.0' . "\r\n";
$headers  .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

mail($to,$subject,$message,$headers); 

Upvotes: 1

pratim_b
pratim_b

Reputation: 1190

Put it inside html tags

//begin of HTML message 
$message = "
<html> 
  <body >
  <input type=\"button\" value=\"Download Report\" onclick=\"location.href='your site with param';\">
  </body> 
</html>
";


 $headers  = "From: $from\r\n"; 
$headers .= "Content-type: text/html\r\n"; 

As pointed in the comment By Fred , avoid using external css. Use inline instead. There are few bolgs available where you can learn about Do's Don't for email css

Upvotes: 0

Paul Dessert
Paul Dessert

Reputation: 6389

You'll need to use an image hosted on your site. Simply point a link to the report. The CSS is useless in the email since it's not defined.

i.e.

<a href="link _to_report"><img src="link_to_image_source" /></a>

Upvotes: 0

Related Questions