...

View Full Version : Creating a mailing list with PHP



IdentityCrisis
05-09-2005, 04:55 PM
Alright, here's what I want to do.

1. User signs up to receive emails from my website (let's assume I'll get a tonne of users).
2. User gets added to a database of users.
3. There is a table in the database containing many different emails. (There are approximately 40 different emails).
4. Based on the users DOB, they will receive a certain email (hense the reason for the different emails in another table).
5. Once a week, the site admin will click on a send email button that will automatically send the email to these users.

I've tried using PHP's mail function, but it doesn't realyl like me doing that ;)

Please, anyone who has experience doing this, I need your help!

Thanks

IC

SeeIT Solutions
05-09-2005, 05:21 PM
I have a mailing list set up and it works fine with the mail function.

What was your problem?

IdentityCrisis
05-09-2005, 05:27 PM
how many users are subscribed?

SeeIT Solutions
05-09-2005, 05:42 PM
couple hundred, y?

IdentityCrisis
05-09-2005, 05:47 PM
oh, just wanted to know if it was a volume issue

currently my list is only up to 70 or so.

The problem I'm having is that some addresses are not having the email delivered to them. I'm doing more research, but I'm currently in the midst of re-writing the script to use BCC instead of sending one email per person.

Thanks for your help, any more tips/hints would be much appreciated!

IC

SeeIT Solutions
05-09-2005, 05:53 PM
I used to use it in Bcc, but decided to change it to a loop using many mail functions, it may take more time etc, but only admins have to use it so they know it is slower than it could be.

Are you sure all the email addresses are correct?

IdentityCrisis
05-09-2005, 06:02 PM
Yeah, I'm sure the emails are correct. That's why it's not making any sense!

Anyways, I'm currently doing it in a loop with mail mail function calls, but I've been advised against that several times.

Can you post a code snippet for me to see how you're doing it?

Thanks

IC

Velox Letum
05-09-2005, 07:13 PM
For a service I am currently coding (I don't have the code with me unfortunately) I am sending alerts when a certain service is updated, and I use BCC for similar emails (of the same service), and mail loops for multiple BCC emails of different services.

Is sendmail configured on your server? You may need to edit php.ini to have your sendmail directory, or you might want to use a SMTP server instead.

IdentityCrisis
05-09-2005, 07:27 PM
Well, I'm using a third party host, so I don't have the ability to configure their server. Senmail is configured, but I think the problem I'm having is due to specific limitations set on the sendmail (I think there's only a cetain number of emails allowed per minute or somthing strange like that.

How would I use another SMTP server?

Can I do that directly from PHP?

Thanks

IC

marek_mar
05-09-2005, 09:44 PM
Youc could do that with fsockopen sending the right headers... but I would need to look things up in a a few places to get you the anwser...

Velox Letum
05-09-2005, 10:09 PM
Code by Terminal, user contributed notes: fsockopen() (http://www.php.net/function.fsockopen)



<?php

$handle = smtp_connect($smtp_server, 25, 30, 1, 1, 1);
echo smtp_command($handle, "EHLO $domain\r\n", 1, 1);
echo smtp_command($handle, "MAIL FROM:<$from_mail>\r\n", 1, 1);
echo smtp_command($handle, "RCPT TO:<$to_mail>\r\n", 1, 1);
echo smtp_command($handle, "DATA\r\n", 1, 1);
echo smtp_command($handle, "$message\r\n.\r\n", 1, 1);
// don't do it like this - it will hang up
// echo smtp_command($handle, "$message", 1, 1);
// echo smtp_command($handle, "\r\n.\r\n", 1, 1);
echo smtp_command($handle, "QUIT\r\n", 1, 1);
smtp_close($handle);


function smtp_connect($host, $port, $timeout=30, $echo_command=False, $echo_response=False, $nl2br=False)
{
$errno = 0;
$errstr = 0;
if($echo_command)
{
if($nl2br) { echo nl2br("CONNECTING TO $host\r\n"); }
else { echo "CONNECTING TO $host\r\n"; }
}
$handle = fsockopen($host, $port, $errno, $errstr, $timeout);
if(!$handle)
{
if($echo_command)
{
if($nl2br) { echo nl2br("CONNECTION FAILED\r\n"); }
else { echo "CONNECTION FAILED\r\n"; }
}
return False;
}
if($echo_command)
{
if($nl2br) { echo nl2br("SUCCESS\r\n"); }
else { echo "SUCCESS\r\n"; }
}
$response = fgets($handle,1);
$bytes_left = socket_get_status($handle);
if ($bytes_left > 0) { $response .= fread($handle, $bytes_left["unread_bytes"]); }
if($echo_response)
{
if($nl2br) { echo nl2br($response); }
else { echo $response; }
}
return $handle;
}

function smtp_command($handle, $command, $echo_command=False, $nl2br=False)
{
if($echo_command)
{
if($nl2br) { echo nl2br($command); }
else { echo $command; }
}
fputs($handle, $command);
$response = fgets($handle,1);
$bytes_left = socket_get_status($handle);
if ($bytes_left > 0) { $response .= fread($handle, $bytes_left["unread_bytes"]); }
if($nl2br) { return nl2br($response); }
else { return $response; }
}

function smtp_close($handle)
{
fclose($handle);
}
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum