Jump to content

mass email


Foser

Recommended Posts

<?php
   $res //your mysql query
   while($row = mysql_fetch_assoc($res)) {
      $content = "Hello %name!\nHow are you?";
      $content = str_replace('%name', $row['name']);
      mail($row['email'], 'hello', $content); //mail to the first user
   }
?>

Link to comment
Share on other sites

You could try something like

 

error_reporting(E_ALL);
//database 
$sql = "SELECT * FROM generalContact";
$result = mysql_query("$sql");

while($row = mysql_fetch_array($result))
{
$email = $row['email'];
$subject = $row['subject'];
$name = $row['firstName'];
}

while(!empty($email)
{
//Mail
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: '.$name.' <'.$email.'>,' . "\r\n"; //This is the TO name and Email
$headers .= 'From:your email address' . "\r\n"; // This is YOUR name and email

$result = mail($email, $subject, $message, $headers);
}
if($result)
{
echo "Mail has been sent";
}
else
{
echo "Mail Failed";
}

Link to comment
Share on other sites

Sending a large number of e-mails with the php mail() function is grossly ineffecient, it's a) slow, and b) a resource hog, not to mention you'll probably run into your script's reaching their memory limit or max execution time.

 

You should look into Pear Mail....

Link to comment
Share on other sites

In 99% of most common cases, you won't be able to send mail with the php mail() function on a windows box... Not unless you configured the mail settings properly in the php.ini file and installed some type of mail server on the box.

Link to comment
Share on other sites

Sending a large number of e-mails with the php mail() function is grossly ineffecient, it's a) slow, and b) a resource hog, not to mention you'll probably run into your script's reaching their memory limit or max execution time.

 

You should look into Pear Mail....

 

would you have any good tutorials which explains PEAR mail?

Link to comment
Share on other sites

Its not just windowsboxes you might run into problems sending the mail. Most, ( ~all here in finland) ISP:s block the gate 25 which is used for SMTP protocol for sending mail. But the ISP:s often provide an smtp relay host that you can send your emails through. You just need to find out the hosts address and configure your mailserver to go through that. For example, I had quite an hassle with my ubuntubox with sendmail...

Link to comment
Share on other sites

I've just built my first real site. I finally decided on a hosting service in part because I found they provided a couple of tools to accomplish just this. My ISP doesn't provide anything but a connection and a small amount of space for my personal pages. If your hosting provider offers something like "Fantastico" you should be able to find a mass emailer. Look for "PHPlist" or something like the Perl mailer that has already been mentioned.

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.