Raymond van Os
Raymond van Os

Reputation: 191

PHP newsletter script with [tags]

I am currently working on a newsletter system in PHP. I can send quickly a lot of email messages to the different customers.

Well, I wondered how I can add [tags] in a textarea. I would instance the tag [name] add to my message and it is intended that each email message the name equals the name of the recipient.

Does anyone perhaps an idea how this is done?

Upvotes: 0

Views: 798

Answers (4)

Raymond van Os
Raymond van Os

Reputation: 191

<head>
    <script type="text/javascript">
        function ModifySelection () {
            var textarea = document.getElementById("myArea");
            if ('selectionStart' in textarea) {
                    // check whether some text is selected in the textarea
                if (textarea.selectionStart != textarea.selectionEnd) {
                    var newText = textarea.value.substring (0, textarea.selectionStart) + 
                        "[start]" + textarea.value.substring  (textarea.selectionStart, textarea.selectionEnd) + "[end]" +
                        textarea.value.substring (textarea.selectionEnd);
                    textarea.value = newText;
                }
            }
            else {  // Internet Explorer before version 9
                    // create a range from the current selection
                var textRange = document.selection.createRange ();
                    // check whether the selection is within the textarea
                var rangeParent = textRange.parentElement ();
                if (rangeParent === textarea) {
                    textRange.text = "[start]" + textRange.text + "[end]";
                }
            }
        }
    </script>
</head>
<body>
    <textarea id="myArea" cols="30" spellcheck="false">Select some text within this field.</textarea>
    <button onclick="ModifySelection ()">Modify the current selection</button>
</body>

Upvotes: 0

Raymond van Os
Raymond van Os

Reputation: 191

I'm so resolved:

page 1:

<table>
       <tr>
           <td>
               <textarea rows="11" cols="70" name="message" id="message" placeholder="your message"></textarea>
           </td>
       </tr>
       <tr>
           <td>
              <script type="text/javascript">
              <!--
                 document.write('<span id="var1" class="insert">[name]</span>, <span id="var2" class="insert">[surnaam]</span>');
              // -->
              </script>
           </td>
       </tr>
</table>

page 2:

 <?php
 $message = $_POST['c_email_message'];
 $mes = $message;
 $mes = str_replace('[voornaam]',$userOb->c_user_name,$mes);                                                                                $mes = str_replace('[achternaam]',$userOb->c_user_surname,$mes);                                                                                


$html_inhoud = '';
$html_inhoud = '
   <table>
       <tr>
           <td>' . htmlentities($mes) . '</td>
       </tr>
   </table>
 ';

Upvotes: 0

Nanne
Nanne

Reputation: 64409

The question is kinda wiiiide, I'm not really sure what the problem is, but this would do the trick. Obviously there is a lot of different things you can do, but start from here and work your way up.

function getMyNewsletter($tags){
    $newsletter = "Hello {$tags['name']}, I hope you liked your {$tags['whattheybought']}. please buy more of my stuff!";
    return $newsletter;
}

$tags = $user->getTagsFromSomewhere();
$mailbody = getMyNewsletter($tags);
yourMailer("SubjectGoesHere",$mailbody,$OtherOptions);

Upvotes: 1

Adriaan
Adriaan

Reputation: 378

When you fetch the message or template from the database and send out the email you can use something like this:

 $message = 'Your HTML Message or Text with your tags like [name]';

 // Replaces the tag [name] with the receiver name from the database 
 $send_message = str_replace('[name]', $fetch['Name'], $message); 

Upvotes: 1

Related Questions