Jump to content

simple php html-mail scriptje


Ultimus

Recommended Posts

All

 

some help would be welcome. I'm having troubles with this simple email script.

 

the idea: would like to make a mailing from a form. This works just fine. I'm having troubles with the mailing it self.

What i posted here: I edited my code to try without concatenating strings (*$_Post varible within xml). This however doesn't work eitherway.

 

tests:

 

all variables get set properly (tested with echo's  :P so I cut them out to save you the reading :-))

connection gets established just fine

All email adresses from the database pass by just fine. (also by echo :-))

 

I'm thinking semantic error but can't find the problem. Can anyone help me?  :'(

 

<?php
    
    //make connection with database
    $con = mysql_connect("XXXXXXXXX","XXXXXXXXXX","XXXXXXXX");
    if (!$con){
        die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("dejuistestudiek", $con);

    //select all emails from mailing table
    if($con){
        $sql = "SELECT * FROM mailing";    
        $result = mysql_query($sql);
        
        //prepare text for html mail
        $text = trim($_POST['TEXT']);
        $text = nl2br($text);
        $text = stripslashes($text);


        if($result){
            
            while($row = mysql_fetch_array($result)){        
                
                // single recipient
                $to  = $row['email'];
                
                // subject
                $subject = 'StuWay - Nieuwsbrief';
                
                // message
                $message = '<html>
                            <head>
                              <title>Birthday Reminders for August</title>
                            </head>
                            <body>
                              <p>Here are the birthdays upcoming in August!</p>
                              <table>
                                <tr>
                                  <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
                                </tr>
                                <tr>
                                  <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
                                </tr>
                                <tr>
                                  <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
                                </tr>
                              </table>
                            </body>
                            </html>';
                                            
                // To send HTML mail, the Content-type header must be set
                $headers  = 'MIME-Version: 1.0' . "\r\n";
                $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
                
                // Additional headers
                $headers .= 'From: Do-Not-Reply@dejuistestudiekeuze.be' . "\r\n";
                // Mail it
                $bool = mail($to, $subject, $message, $headers);
                
            }
        }
    }

?>

Link to comment
Share on other sites

You set the variable $bool and did nothing with it and you never called it. I removed it I am assuming you were trying to put in an error catch for it but I just removed it.

 

<?php
    
    //make connection with database
    $con = mysql_connect("XXXXXXXXX","XXXXXXXXXX","XXXXXXXX");
    if (!$con){
        die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("dejuistestudiek", $con);

    //select all emails from mailing table
    if($con){
        $sql = "SELECT * FROM mailing";    
        $result = mysql_query($sql);
        
        //prepare text for html mail
        $text = trim($_POST['TEXT']);
        $text = nl2br($text);
        $text = stripslashes($text);


        if($result){
            
            while($row = mysql_fetch_array($result)){        
                
                // single recipient
                $to  = $row['email'];
                
                // subject
                $subject = 'StuWay - Nieuwsbrief';
                
                // message
                $message = '<html>
                            <head>
                              <title>Birthday Reminders for August</title>
                            </head>
                            <body>
                              <p>Here are the birthdays upcoming in August!</p>
                              <table>
                                <tr>
                                  <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
                                </tr>
                                <tr>
                                  <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
                                </tr>
                                <tr>
                                  <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
                                </tr>
                              </table>
                            </body>
                            </html>';
                                            
                // To send HTML mail, the Content-type header must be set
                $headers  = 'MIME-Version: 1.0' . "\r\n";
                $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
                
                // Additional headers
                $headers .= 'From: Do-Not-Reply@dejuistestudiekeuze.be' . "\r\n";
                // Mail it
                mail($to, $subject, $message, $headers);
                
            }
        }
    }

?>

 

Hope I could be some help.

Thanks,

Colton Wagner

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.