Hi,

A friend asked me to do a newsletter script for him, because he doesn't know PHP. I did it, but there are still some little problems I would like to correct. First, the source-code of the mail writing page :

<?php
include('db.php');
$message = $_POST['message'];
$titre = $_POST['titre'];
$compteur = 1;

//adresses
$sql = mysql_query('SELECT mail FROM newsletter_etienne');
if($sql) {
    while ($adresse = mysql_fetch_assoc($sql))
    {
        $mail = $adresse['mail'];
        $expediteur = "From: Newsletter Théâtre Marston <newsletter@site.com>\nMime-Version: 1.0\nContent-Type: text/html; utf_8encode\n";
        mail($mail, $titre, $message, $expediteur);
        echo '#' . $compteur . ' - ' . $mail . ' : envoyé avec succès !<br />';
    }
}else{
mysql_error();
exit();
}

if(mail == true) {
$compteur++;
echo 'Total #' . $compteur . ' - emails envoyés avec succès !';
}else{
echo 'Les emails n'ont pas pu être envoyés!!';
}
mysql_close();
?>

First problem : the emails are received long after I send them, from 20 minutes later to one day later.
Second : the emails are sent two times each ; the first one is the good, and the second is empty ...
Third : there is " \ " before each " ' ". I tried to but a stripslashes, but it changes nothing. And the special characters are not displayed as they should. For example : "ç è é à ù ë Ö Ü" ... And there is a "Spam Filtered (ID:1941611)" at the end of each message ...

There is a lot of problems, but I really don't know how to fix them ... Can you help me, please ?

Thanks,

Sam

PS : there is some French parts in the code, sorry, it's because I usually speak French and my friend too, that's why it's written if French !

    The time delay is your mail server.
    You are probably on a shared host that is bogged down - call you hosting company about that issue.

    As for the duplicate mails being sent out, check your newsletter_etienne table for duplicate entries, with one of each missing a message.

    "Spam Filtered (ID:1941611)" is most likely being tacked on to the message by your mail server - call your web host for an answer on this one.

      I checked my table, and my email is there twice, but I receive 4 mails ...

      I changed the charset to utf-8, now the special characters appear. One problem less. My code is now more like this :

      <?php 
      if (isset($_POST_['message']))
      {
      include('db.php');
      $message = $_POST['message'];
      $titre = $_POST['titre'];
      $compteur = 1;
      
      //adresses
      $sql = mysql_query('SELECT mail FROM newsletter_etienne');
      if($sql) {
      	while ($adresse = mysql_fetch_assoc($sql))
      	{
      		$mail = $adresse['mail'];
      		$expediteur = "From: Newsletter Théâtre Marston <newsletter@site.com>\n";
      		$expediteur .= "Mime-Version: 1.0\n";
      		$expediteur .= "Content-Type: text/html; charset=utf-8\n";
      		mail($mail, $titre, $message, $expediteur);
      		echo '#' . $compteur . ' - ' . $mail . ' : envoyé avec succès !<br />';
      	}
      }else{
      mysql_error();
      exit();
      }
      
      if(mail == true) {
      $compteur++;
      echo 'Total #' . $compteur . ' - emails envoyés avec succès !';
      }else{
      echo 'Les emails n\'ont pas pu être envoyés!!';
      }
      mysql_close();
      }
      else
      {
      	echo "La page à laquelle vous tentez d!'accéder ne peut être affichée dans les circonstances.";
      }
      ?>

      I have a few problems remaining ...

      Here is the email I sent to test :

      Message-Id: <20080604043001.C45F318B2B@node2.byetcluster.com> Date: Wed, 4 Jun 2008 00:30:01 -0400 (EDT) Voyons voir cette fois, j\'espère que ça va marcher 🙂 Spam Filtered (ID:1941611)

      The bold part is what I sent and I don't know from where the rest of the message is coming. So ...

      1. Can I Delete the "Message-Id: <20080604043001.C45F318B2B@node2.byetcluster.com> Date: Wed, 4 Jun 2008 00:30:01 -0400 (EDT)" and "Spam Filtered (ID:1941611)" ?

      2. Can I get rid of the " \ " before each " ' " ?

      3. The email is still sent twice, one with my message and the other, empty, with only the "Message-Id: <20080604043001.C45F318B2B@node2.byetcluster.com> Date: Wed, 4 Jun 2008 00:30:01 -0400 (EDT) Spam Filtered (ID:1941611)". Can I have only ONE mail sent at the time ?

      Thank you !

      Sam

        Write a Reply...