-1

Possible Duplicate:
Php mail: how to send html?

I want to use the Mail() function in PHP but I am having some difficulties to include a link and a variable in the messagge.

$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";

How can I send the message below?

Please click <a href="http://domain.com/verify.php?token=$token">here</a> to veify.
Community
  • 1
  • 1
EnexoOnoma
  • 8,454
  • 18
  • 94
  • 179

3 Answers3

1

You would have to create an HTML email which is pretty much a lot of work if you want to do it from scratch and so many things can actually go wrong.

Instead of doing it by hand use PHPMailer (http://phpmailer.worxware.com/) along with its MsgHTML() method to add HTML content to the message body.

0
$var = "http://domain.com/verify.php?token=$token";
$message = "Please click <a href=\"{$var}\">here</a> to veify.";
Ahmed Jolani
  • 2,872
  • 2
  • 20
  • 24
0

Try this

$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$message .="Please click <a href=\"http://domain.com/verify.php?token=\"{$token}\">here</a> to veify.";
$from = "someonelse@example.com";
$headers = "From:" . $from;
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\n";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
Paul Dessert
  • 6,363
  • 8
  • 47
  • 74