PHP email verification – how to organize a message? using html tags

emailPHP

when I send a user an email verification message, how do I construct it to look something like this:

alt text

How do I add links? using tags? and newlines?

$message = 'Thanks for signing up!' - a newline afterwards...
then blablablah *link to confirmation*

I would really appreciate any kind of help in this.

Best Answer

It depends on the type of email you are sending. Modern email clients supports 2 types of email:

  • Text - in this case you just add link to your message like raw text. No special formating is required, but it'll depend on email client to handle the link. Most email clients will interpret string starting from http:// as link.
  • Html - in this case just add the link as usual html code <a href="...">...</a>. Most email agents undestand basic html well.

By default mail() function sends email in raw text. Here is small example:

$lines = array(
    "Hello!",
    "Your password is ...",
    "Click following link to unsubscribe:",
    "http://your_site/unsubscribe?..."
);
$body = implode("\r\n", $lines); ## join lines
mail($to, $subject, $body);      ## and send text email