IER506 Posted July 7, 2010 Share Posted July 7, 2010 Good morning team. I'm facing a problem and your help is appreciated. I have some text stored in a database in the following format: THIS IS A TEST </ br> THIS IS ANOTHER TEST</ br> 12345 </ br> THIS IS ONE MORE TEST Then I'm retrieving this content with a query and I have a button called Email with which I want to send the text to an email. Unfortunately I cannot add the correct format and I cannot have new lines in the email. I've tried removing all html tags, I've tried replacing br with \r\n but the result is always the same. When outlook opens the content is displayed in one line! Can you please propose a solution? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/206995-email-problem/ Share on other sites More sharing options...
Adam Posted July 7, 2010 Share Posted July 7, 2010 How are you sending the email, what are headers are you sending? Quote Link to comment https://forums.phpfreaks.com/topic/206995-email-problem/#findComment-1082382 Share on other sites More sharing options...
myrddinwylt Posted July 7, 2010 Share Posted July 7, 2010 Use this library for sending your e-mail instead of the internal "mail()" function. You havn't stated what method you are using to send e-mail, but regardless, this is the best solution for sending mail as it supports pretty much every type of connection method, and it can authenticate (aka, just pass it the same credentials you would pass Outlook, etc). PHP Mailer 2.0.4 for PHP4 PHPMailer 5.1 for PHP5[/code] For examples and information about the author for this free module, visit Worx International Inc. Quote Link to comment https://forums.phpfreaks.com/topic/206995-email-problem/#findComment-1082386 Share on other sites More sharing options...
Adam Posted July 7, 2010 Share Posted July 7, 2010 Whilst it may make it easier, perhaps learning a bit more of the 'internal' stuff is good for a solid understanding. Quote Link to comment https://forums.phpfreaks.com/topic/206995-email-problem/#findComment-1082388 Share on other sites More sharing options...
IER506 Posted July 7, 2010 Author Share Posted July 7, 2010 It seems that I didn't explained my problem well enough and I am sorry for that. This is what I want to have in my code: $email = '<a href= "mailto:?subject=Message number '.$dbmid.' from '.$dbdes.'&body='.$dbmsg.'" >Email</a>'; echo $emai;l Where: $dbmid is a number in my db $dbdes is a word in my db and $dbmsg is the formatted message mentioned before The problem is in $dbmsg. When Outlook starts I cannot have new lines. Quote Link to comment https://forums.phpfreaks.com/topic/206995-email-problem/#findComment-1082395 Share on other sites More sharing options...
IER506 Posted July 7, 2010 Author Share Posted July 7, 2010 Solution found: //First we replace all <br /> tags with %0D%0A. %0D%0A is the new line for outlook... $mailreplacebr = str_replace("<br />","%0D%0A", $dbmsg); //Then we remove the remaining html elements $emailbody = strip_tags($mailreplacebr); //Finally we generate the email link $emailoption = '<a href= "mailto:?subject='$dbmid.' from '.$dbdes.'&body='.$emailbody.'" >Email</a>'; Quote Link to comment https://forums.phpfreaks.com/topic/206995-email-problem/#findComment-1082416 Share on other sites More sharing options...
myrddinwylt Posted July 7, 2010 Share Posted July 7, 2010 Hello, Your question isn't really PHP related then, it has to do with the correct syntax for the MAILTO: link. In either case, to insert a new line, using a MAILTO link, you would use the following: %0A For more information about the MAILTO link syntax, please see This Page . It is actually a link located on the Institute of National Agriculture --- dunno why.... but it's very technical FAQ on the syntax and is not related to the content of their site in any way. In your message above, you have </ br>, but in your code you are searching for <br />. Since I am not the greatest with RegEX, here is a manual method of assuring that characters get replaced properly. $mailreplacebr = str_replace("<br />","%0D%0A", $dbmsg); $mailreplacebr = str_replace("<br/>","%0D%0A", $mailreplacebr); $mailreplacebr = str_replace("<br>","%0D%0A", $mailreplacebr); $mailreplacebr = str_replace("</ br>","%0D%0A", $mailreplacebr); $mailreplacebr = str_replace("</br>","%0D%0A", $mailreplacebr); $mailreplacebr = str_replace("\r\n","%0D%0A", $mailreplacebr); $mailreplacebr = str_replace("\n","%0D%0A", $mailreplacebr); For information on how to send mail using PHP, I am reposting the links I did above because there is an error in the last 2 links. PHP4: PHPMailer 2.0.4 PHP5: PHPMailer 5.1 For examples and information about the author for this free module, visit Worx International Inc. Quote Link to comment https://forums.phpfreaks.com/topic/206995-email-problem/#findComment-1082447 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.