Page 1 of 1

Some problems with the mail() function

Posted: Sun Jun 01, 2008 9:18 pm
by sam_1421
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 :

Code: Select all

<?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 !

Re: Some problems with the mail() function

Posted: Mon Jun 02, 2008 6:51 am
by sam_1421
Could you help me, please ? I really don't understand what won't work in my script :(

Re: Some problems with the mail() function

Posted: Mon Jun 02, 2008 7:47 am
by Chris Corbyn
You need to specify the charset and content-type ;)

Re: Some problems with the mail() function

Posted: Mon Jun 02, 2008 9:46 pm
by sam_1421
Yes, it's done !

Code: Select all

$expediteur = "From: Newsletter Théâtre Marston <newsletter@site.com>\nMime-Version: 1.0\nContent-Type: text/html; utf_8encode\n";

Re: Some problems with the mail() function

Posted: Tue Jun 03, 2008 7:18 am
by Chris Corbyn
That's not right.

Code: Select all

$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";

Re: Some problems with the mail() function

Posted: Tue Jun 03, 2008 11:43 pm
by sam_1421
You were right, now the special characters appear ! But there's still a few problems ... 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

Re: Some problems with the mail() function

Posted: Thu Jun 05, 2008 5:12 pm
by sam_1421
Up please ;)

Re: Some problems with the mail() function

Posted: Thu Jun 05, 2008 6:08 pm
by Eran
I suggest you use a ready made mail component, such as Zend_Mail or ezComponents mail

Re: Some problems with the mail() function

Posted: Thu Jun 05, 2008 6:17 pm
by sam_1421
I could, but I don't know if all these pre-made scripts will work on my friend's server ...