Reputation: 23662
when I send a user an email verification message, how do I construct it to look something like this:
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.
Upvotes: 0
Views: 320
Reputation: 5349
To specifically address your question regarding new lines, you have a few ways you can do it:
1
$message = 'Thanks for signing up!
blablablah *link to confirmation*'
Use single quotes and a simple <enter>
at the end of the line.
2
$message = "Thanks for signing up!\n\r
blablablah *link to confirmation*"
Use double quotes, \n\r (this creates the new line - actually a line feed and a carriage return) and a simple <enter>
at the end of the line (this is purely for your own readability.
3
Upvotes: 0
Reputation: 316999
Like the others said, just send the eMail and let the client figure out what is clickable.
Just create a simple textfile template in a folder accessible by your mail script, e.g.
Thanks for signing up
This is your login data
------------
u: [username]
p: [password]
-------------
Active your account by clicking [activation-link]
Then in your mailing script, you load this file and str_replace()
the placeholders. This way, you dont have to garble your mail script with the email message and can easily maintain any changes without having to touch your script. You also dont have to bother coding linebreaks into it.
I strongly discourage using HTML mail. There is a huge uncertainty on the receiving end. Users may access their mail with clients unable or disabled to render HTML, so you will have to send the mail with alternate text (multipart). In addition, rendering of HTML in clients is a major pain.
Upvotes: 0
Reputation: 28723
It depends on the type of email you are sending. Modern email clients supports 2 types of email:
http://
as link.<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
Upvotes: 3
Reputation: 43814
If you send it with plain-text email programs nearly always will convert a URL into a clickable link. Otherwise you can send an HTML email.
How to organize your code:
Smarty templates are also great for this. You can have a .tpl template that you pass in variables to, so your email templates are in their own files that have only the tags/fields needed. Then the PHP can pull in this content, parse it, and send the body as the email.
Upvotes: 1
Reputation: 33171
You have several options for this.
1.You can use plain text as the mime type, then setup your $message var like:
$message = "Thank you... \n\r";
$message.= "next line... \n\r";
or use heredoc
$message = <<<BLOCK
Thank you...
next line...
BLOCK;
Most email programs should convert the link, I think. But if you need to do that explicitly,
2.then you could always use a html mime type for your email and just provide it basic HTML as the message body.
Upvotes: 0
Reputation: 7063
Just construct the link and add it to the email body. The mail client figures out what is a link. Alternatively you can go down the full html email route.
Upvotes: 0