Mark Railton
Mark Railton

Reputation: 522

build html link with variable inside php mail

Using the PHP mail function I need to send out an email that includes a link back to a record that has been modified, the link will need to contain the $id of the record that was modified on the database.

So far I have the email built, however am not sure on how I can include the link with variable.

mail('[email protected]', 'Visitor Record Updated', "Hello,\r\n\r\nThe visitor record for " . $firstname . " " . $lastname . " Has been updated.\r\n\r\nYou can view the changes" . $url ."\r\n\r\nThank You");

That is how I plan to have the email sent, however how can i build the $url variable so that it sends the link as

http://app.site.com/visitor-view.php?id=$id

Upvotes: 0

Views: 1107

Answers (2)

Kumar V
Kumar V

Reputation: 8830

You can send simple link. But it may not clickable in some email provides. So You have to send as html email:

Refer below link for more details

http://css-tricks.com/sending-nice-html-email-with-php/

If you want to add CSS, then you can add as inline style.

From above link i prepared for your question:

** prepare content of email**

$content ="<html><head><title>Welcome to Mysite</title></head>
<body>
<p>Hello,<br/><br/>
  The visitor record for " . $firstname . " " . $lastname . " Has been updated.<br/><br/>
  You can view the changes <a href='".$url."'>Here</a></p>

<p>Thank You</p>
</body></html>"; 


$to = '[email protected]';

$subject = 'Visitor Record Updated';

$headers = "From: [email protected]\r\n";
$headers .= "Reply-To: [email protected]\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

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

Upvotes: 0

Jori
Jori

Reputation: 56

mail('[email protected]', 'Visitor Record Ppdated', "Hello,\r\n\r\nThe visitor record for " . $firstname . " " . $lastname . " Has been updated.\r\n\r\nYou can view the changes: http://app.site.com/visitor-view.php?id=" . $id ."\r\n\r\nThank You");

Upvotes: 2

Related Questions