Page 1 of 1
html in php sendmail?
Posted: Sat Oct 28, 2006 5:24 pm
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
Posted: Sat Oct 28, 2006 7:02 pm
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.
Posted: Sat Oct 28, 2006 7:19 pm
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);
?>
Posted: Sat Oct 28, 2006 7:21 pm
by volka
akimm wrote:htmlentities(mail($to, $subject, $msg, $mailheaders));
What's that supposed to do?
What's does htmlentities do to bool?
Posted: Sat Oct 28, 2006 7:34 pm
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.
Posted: Sat Oct 28, 2006 7:36 pm
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?
Posted: Sat Oct 28, 2006 7:38 pm
by akimm
If it would make you happy, I'll remove my posts, and you can go ahead and give him the correct method.
Posted: Sat Oct 28, 2006 7:44 pm
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.
Posted: Sun Oct 29, 2006 4:22 am
by Ollie Saunders
volka wrote:It's neither scolding nor goofing on you.
Well..it did sound like you were.
Keep going akimm!
Posted: Sun Oct 29, 2006 4:39 am
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.
Posted: Sun Oct 29, 2006 4:59 am
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
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.
Posted: Sun Oct 29, 2006 6:02 am
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
