PHP Mail - with HTML...?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

PHP Mail - with HTML...?

Post by simonmlewis »

Code: Select all

<?php
$to = 'email@domain.com';
 
$subject = 'Website Change Reqest';
 
$headers = "From: noreply@domain.com";
$headers .= "Reply-To: noreply@domain.com";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
 
$message = '<html><body>';
$message .= '<h1>Hello, World!</h1>';
$message .= '</body></html>';
mail($to, $subject, $message, $headers);
?>
Hello
I want to be able to send out emails via the mail script, but in HTML.

Having read some scripts, it seems pretty straight forward, but the above produces nothing.

Have I missed something?
Do I need to enable something else on the server?

Hope someone can help point me in the right direction. Once I've got this cracked, email marketing will be alot easier!!

Simon
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: PHP Mail - with HTML...?

Post by mikosiko »

simonmlewis wrote:Hello
I want to be able to send out emails via the mail script, but in HTML.
. Once I've got this cracked, email marketing will be alot easier!!

Simon
read here : http://www.php.net/manual/en/mail.requirements.php

.... are you tried to look into PHPMailer or SwiftMailer? ... seems better options than mail()
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: PHP Mail - with HTML...?

Post by simonmlewis »

That page just seems to state that for the mail to work, things must be installed.
Mail *does* work - but html format isn't doing anything.

We dont want to install further software on the web server. Our hosts did suggest those tools, but if we can just get HTML to work - we dont need it.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: PHP Mail - with HTML...?

Post by mikosiko »

simonmlewis wrote:That page just seems to state that for the mail to work, things must be installed.
Mail *does* work - but html format isn't doing anything.

We dont want to install further software on the web server. Our hosts did suggest those tools, but if we can just get HTML to work - we dont need it.
well....
Having read some scripts, it seems pretty straight forward, but the above produces nothing.
is different to:
Mail *does* work - but html format isn't doing anything.
hence my mistake....
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: PHP Mail - with HTML...?

Post by simonmlewis »

Mmmmm maybe.

I said the above does nothing. Which is correct.

Mail works fine when i do 'plain text'.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

[RESOLVED] Re: PHP Mail - with HTML...?

Post by simonmlewis »

Thanks to all who responded.
Answer was that it should be \n not \n\r.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply