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: [email protected]' . "\r\n";
                // Mail it
                $bool = mail($to, $subject, $message, $headers);
                
            }
        }
    }

?>

Link to comment
https://forums.phpfreaks.com/topic/216582-simple-php-html-mail-scriptje/
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: [email protected]' . "\r\n";
                // Mail it
                mail($to, $subject, $message, $headers);
                
            }
        }
    }

?>

 

Hope I could be some help.

Thanks,

Colton Wagner

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.