Jump to content

Email all users in MySQL Database


premora

Recommended Posts

Hi there everyone.  I'm really confused about this as I want to email eveyone in my DB when a new Event is created by a member.

 

I have a test code which I used to make sure it works and it sends to 5 email addresses (which is all of them) in the test table.  This works fine.  All members with a 0 get the mail.

 

So I now just took the code and changed the table name (obviously!!) and put it in my live site which has 50 members so far.  It now doesn't send any emails???  Not sure why this is as the code is exactly the same (except the table name).

 

$result = mysql_query("SELECT email FROM membership WHERE send_as_email = '0'");

 

while ($row = mysql_fetch_array($result)) {

  sendMail($row[0]);

}

mysql_free_result($result);

 

function sendMail($to){

$subject = 'New Event Created;

$message = "Hi there,\n

Just letting you know of a new Event that has been created.\n

Title: $title\n

Town: $town\n

Date: $date_convert\n

For more details or to attend this Event, please login \n

Many thanks\n

The  Team\n

\n

****************************************************************************\n

THIS EMAIL IS AUTOMATED.  DO NOT REPLY.\n

To turn notifications off, change the notification settings in your Profile.\n

****************************************************************************\n";

$headers = 'From: members@mysite.co.uk' . "\r\n" .

'X-Mailer: PHP/' . phpversion();

 

mail($to, $subject, $message, $headers);

Link to comment
Share on other sites

Hi,

 

It sounds like your server does not want to send the email and probably has nothing to do with the database/php code.

 

I would first make sure to see if you are allowed to use SMTP on your web server, if you are make sure that there is nothing blocking the emails being sent. I know some servers will limit to say 10 emails within a set amount of time so you are not using your server to send mass spam emails.

 

Worth checking both.

 

Hope this Helps

 

Regards

Albos

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.