Dynadot โ€” .com Registration $8.99

Need help with PHP mail() function

Spaceship Spaceship
Watch

aznchong91

Established Member
Impact
25
Hi, I am trying to send an automated email from a registration form. How do I become capable to use HTML in my email? Here is what I have, please tell me what I am doing wrong!

PHP:
$subject="DONOTREPLY:Verification Email";
$text='Thank you for taking the time to register, you are almost ready to go. Just click the link below or paste it into your browser if it does not work. Thank you! <br><br><a href="http://www.thelinkhere" target="_blank">http://www.thelinkhere</a><br><br><br>If you did not register, just ignore this message. <br><br>Yours truly, <br><i>Dev Team</i>';
$body=addslashes(trim(htmlspecialchars($text)));
$to=$email;
$headers  = 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n";
$headers .= 'Reply-To: '.$to . "\r\n";
$headers .= 'From: Development Team' . "\n";
mail($to, $subject, $body, $headers);

it is sending the email fine, everything is fine, but the HTML is not being parsed. I would really appreciate any help!
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
if the user doesnt recieve html emails, it wont work. is that ur problem?
 
0
•••
yea, the HTML isn't turning into visual looks, ie <br> stays <br>. Can somebody please help me?
 
0
•••
You need to use SMTP. Google it.
 
0
•••
so basically, my webhost needs to have SMTP enabled, is that right?
 
0
•••
where is the $email variable coming from? try the GET globals
 
0
•••
Try not using "" in your HTML coding within the PHP variables!!!
Just do something like this:
<a href=www.blah.com>yeah</a>

Like that! That'll probably fix it!!!
 
0
•••
no, no, no, you guys don't understand. The email is being sent fine (the $email is from a $_POST variable), it's just the HTML is not being turned into actual output, for example <br> stays <br>. I appreciate your help, but it isn't exactly what I needed. Does anybody else have any suggestions/help?
 
0
•••
I only see one thing that could be causing it not to be parsed like html that is that you do not have the neccessary tags for html to be used. Even though it is an email you still have to define things such as <html><head><title><body> in order for it to work correctly. Try adding those tags where needed (like a webpage) then see what happens.

Change $text like below and it should work
PHP:
$text='<html><head><title></title></head><body>Thank you for taking the time to register, you are almost ready to go. Just click the link below or paste it into your browser if it does not work. Thank you! <br><br><a href="http://www.thelinkhere" target="_blank">http://www.thelinkhere</a><br><br><br>If you did not register, just ignore this message. <br><br>Yours truly, <br><i>Dev Team</i></body></html>';
 
Last edited:
0
•••
Wow I've never been able to use " in PHP variables!
You may have to do the \n command for breaking if <br> won't work!?
 
0
•••
ah, yes, I see, I forgot about that! thx! and to use quotes inside PHP variables, just put a \ before them, like this: \"

EDIT::
well, \n doesn't seem to work, it isn't being parsed either! AHHHH!!!

Twizted: that didn't work either, it still came up as text, thx though!
 
Last edited:
0
•••
This problem is quite simple. On line 3 you have the following:-

PHP:
$body=addslashes(trim(htmlspecialchars($text)));

Why are you using htmlspecialchars() that function is meant to be used if you do not want the html parsed the result being (you will need to scroll along to see the problem):-

Code:
Thank you for taking the time to register, you are almost ready to go. Just click the link below or paste it into your browser if it does not work. Thank you! <br><br><a href="http://www.thelinkhere" target="_blank">http://www.thelinkhere</a><br><br><br>If you did not register, just ignore this message. <br><br>Yours truly, <br><i>Dev Team</i>

As you can see it is no longer html.

To fix the problem simply change that line to:-

PHP:
$body=addslashes(trim($text));

iHosty said:
Wow I've never been able to use " in PHP variables!
You may have to do the \n command for breaking if <br> won't work!?

you can use a slash to escape any char that has special meaning in php to stop it being used by php.

the \n command would only show it as a new line IF it was in plain text and not html. If you used it on an html sheet then the new line could be seen in the source but not the page.

iHosty said:
Try not using "" in your HTML coding within the PHP variables!!!
Just do something like this:
<a href=www.blah.com>yeah</a>

Like that! That'll probably fix it!!!


That makes no odds especially if they are enclosed in the other quotes. If they are not but are escaped it will also work.

For example you can have any of the following:-

'Paul said "Hi" to peter'
'Paul said \'Hi\' to peter'
"Paul said \"Hi\" to peter"
"Paul said 'Hi' to peter"
 
Last edited:
0
•••
ah, yes, I noticed not long ago, I changed that, but it still doesn't work. I also tried \n in place of <br> and it still didn't work. Thx though!
 
0
•••
i have tried it personally and it worked 100%
 
0
•••
it must be something to do with my webhost, is there something that has to be enabled, maybe PHP 5.x or something?
 
0
•••
no there does not seem to be any difference.

Send a message and get the source of the message (in outlook express go to your inbox so that you can see it in the list, right click on the email and click properties then the details tab, then click message source) Copy the source and paste it in the code tags here (obviously edit out email address etc).
 
0
•••
never mind, it works now, I don't know what the heck was wrong before, I didn't change a thing... thx for your help though!
 
0
•••
no problem, the fact that it is working now is all that matters :)
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Unstoppable Domains
Domain Recover
DomainEasy โ€” Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back