HomeBoard indexphp forum :: php codingPHP coding => Mail i need help making an email button inside a table with data pulled from database


hello i have a page with table with content pulled from database. id like that for each row, there’d be a button that sends email to that user

the initial page with the form is in separate page, this is for the admin page. below is the code for the table on the admin side

this si the code for the table

<?php if(!empty($stores)): ?>
                <?php foreach($stores as $k=>$v): ?>
                <tr class='<?php echo ($k%2==0) ? 'odd':'even'; ?>'>
                    <td><?php echo $v['name']; ?></td>
                    <td><?php echo $v['address']; ?></td>

                    <td><?php echo $v['telephone']; ?></td>
                    <td><?php echo $v['email']; ?></td>
                    <td><?php echo $v['website']; ?></td>
                    <td class="acenter"><?php echo ($v['approved']) ? 'Yes' : 'No' ; ?></td>
                    <td class="actions">
                        <a href='./stores_edit.php?id=<?php echo $v['id']; ?>'><i class="icon-pencil"></i></a>
                        <a href='javascript:delItem(<?php echo $v['id']; ?>)' class="confirm_delete"><i class="icon-trash"></i></a>
                        <?php if(!$v['approved']) : ?>
                        <a href='?action=approve&amp;&id=<?php echo $v['id']; ?>&search=<?php if(isset($_REQUEST['search'])) { echo $_REQUEST['search']; } ?><?php if(isset($_REQUEST['page'])) { echo "&page=".$_REQUEST['page']; } ?><?php if(isset($_REQUEST['sort'])) { echo "&sort=".$_REQUEST['sort']; } ?><?php if(isset($_REQUEST['filter'])) { echo "&filter=".$_REQUEST['filter']; } ?>'><?php echo $lang['ADMIN_APPROVE']; ?></a>
                        <?php endif; ?>
                        <a href= 'mail($v['email'], sprintf("subject here"), sprintf("email body here"),"From: Retailer@blablaba.com", $headers);><i class="icon-envelope"></i></a>


                <?php endforeach; ?>
            <?php else: ?>
                    <td colspan="7"><?php echo $lang['ADMIN_NO_STORES']; ?></td>
            <?php endif; ?>

so i get the mail icon to work, but when i click it the link just redirects to homepage and the URL has double slash like so


of course, no one actually got any email too. anyone have any idea?


At least you have to use PHP-tags to run enclosed PHP-code, just like on the other parts of your file


But PHP runs immediatly with the script, so inserting the code within a link just runs the code and returns nothing within the href-tag to generate a trigger for a click.


ty for the reply. what do you mean by “PHP runs immediatly with the script”?

this is just snippet of the code, its not the entire page.


You go to the URL the script lies behind, the script runs. Your programming style, embedding code in links that should obviously run after the link is clicked, shows you are missing the basic priciples of the server-client-model that PHP relies on.


hmm, yeah im still new.