html in php sendmail?

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
User avatar
potato
Forum Contributor
Posts: 192
Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree

html in php sendmail?

Post by potato »

Hi,

i want to send a mail thru php in html, but the mail itselfs dysplays the html-code, not the result.
This is my code:

Code: Select all

$message = "<table><tr><td>blablah</td></tr></table>";

mail( "recipient@mail.com", "subject",
$message, "From: no-reply@mytuningcar.be" );
except of showing the table it shows <table><tr><td>blablah</td></tr></table>

What i have to change?

Friendly greetz
tom
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Post by akimm »

This mail function is not safe. I wouldn't recommend it, I would instead recommend swiftmailer, or another mailing program like that.

however, i'll be back in a few minutes with a code that you can use for now, it will send the mail just like i said, not the best way of doing things.
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Post by akimm »

Code: Select all

<?php

#as for the table prob, why not try something like htmlentities()
#or strip_tags() depdning on what you want to do.  
#if you want to rid the message of HTML in general use strip_tags
#if you want to make all characters remain HTML when they should use htmlentities()
$msg = "#given subject\r\n"; 
$msg .= "Sender's NAME: \t{$_POST['name']}\r\n"; 
$msg .= "Sender's EMAIL:\t{$_POST['sender_email']}\r\n"; 
$msg .= "Sender's TITLE:\t{$_POST['title']}\r\n"; 
$to = "#email\r\n"; 
$subject = "##your subject\r\n"; 
$mailtoheaders = "#from who <##email>\r\n"; 
#if you have a $_POST['sender_mail'] you can reply to them in your mail 
$mailheaders .= "Reply-To: {$_POST['sender_email']}\r\n"; 
mail($to, $subject, $msg, $mailheaders); 
?>
Last edited by akimm on Sat Oct 28, 2006 7:40 pm, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

akimm wrote:htmlentities(mail($to, $subject, $msg, $mailheaders));
What's that supposed to do?
http://de2.php.net/manual/en/function.mail.php wrote:bool mail ( string to, string subject, string message [, string additional_headers [, string additional_parameters]] )
What's does htmlentities do to bool?
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Post by akimm »

htmlentities:
htmlentities -- Convert all applicable characters to HTML entities


strip_tags:
strip_tags -- Strip HTML and PHP tags from a string


Volka, instead of scolding me, tell him the right way, I thought htmlentities() would allow him to keep the HTML while retaining his email info.


strip_tags I figured would remove the HTML if he so chose.
Last edited by akimm on Sat Oct 28, 2006 7:37 pm, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

You're passing the return value of mail() to htmlentities().
The return value of mail() is a boolean, i.e. TRUE or FALSE.
so what is htmlentities(true)/htmlentities(false) about?
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Post by akimm »

If it would make you happy, I'll remove my posts, and you can go ahead and give him the correct method.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

It's neither scolding nor goofing on you.
akimm wrote:I would instead recommend swiftmailer, or another mailing program like that.
I second that.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

volka wrote:It's neither scolding nor goofing on you.
Well..it did sound like you were.
Keep going akimm!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

ole wrote:
volka wrote:It's neither scolding nor goofing on you.
Well..it did sound like you were.
Where?
If you mean the two simple questions then I really don't care if you feel that way. I won't stop asking about the basics. It's not to make you feel bad or me feeling better but to make you think about what can and what can't be - from the basics, nothing sophisticated.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

OK, I understand you motivations but the subject of your lesson clearly wasn't appreciating it and yet you continued. I won't say anymore.

To make things clear for akimm:

Code: Select all

$someHtml = '<a name="foo"><b>wee!</b></a>';
echo htmlspecialchars($someHtml, ENT_QUOTES);
Outputs:

Code: Select all

<a name="foo"><b>wee!</b></a&gt

Code: Select all

echo htmlspecialchars(true); // Outputs: 1 
echo true; // Outputs: 1
...shows that htmlspecialchars has no effect on a boolean and is an unnecessary step.
htmlspecialchars is better than entities but with either once you should always specify the ENT_QUOTES param.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Guys there's nothing wrong with suggesting what to look at in the code without giving a direct answer. If it makes you do some reading and think about it then we've succeeded in helping you to learn. We're her to help you to learn; not to give you all the answers ;)
Post Reply