Jump to content

Email problem


IER506

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>'; 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.