1

I have a contact form on my website so users can send me an email but I have run into a problem.

I want to use an HTML link inside the email and I also want the content the user is sending to me to be formated how they would like it.... let me explain.

If a user sends this:

Hello World!

Isnt it a great Day?

without using headers to enable html, then it says formated like that when it reaches me.

If I use headers (MIME) to enable html, to also include a link in the email (which I would like to do), then it reaches me as:

Hello World!Isnt it a great Day?

How can I include html, and also keep the email formatted properly?

Thanks

And hopefully all this makes sense :S

1
  • 1
    Well, what hinders you to learn HTML and then make use of the langauge? Which part of HTML in specific don't you understand to express a line break or paragraph? Commented Jun 17, 2012 at 10:42

1 Answer 1

2

Use nl2br on your message - http://php.net/manual/en/function.nl2br.php

It will replace all newlines with HTML <br>

$message = nl2br($message, false);

The second parameter *is_xhtml* is optional if you want to send an HTML email instead of XHTML

Sign up to request clarification or add additional context in comments.

7 Comments

you should not use XHTML in emails.
@hakre that's what nl2br returns according to examples in the PHP manual.
Read close, test yourself, use the parameter that's needed to fix/control this.
@hakre right :) just noticed after sent the message - $is_xhtml has to be set to false
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.