Foser Posted January 21, 2008 Share Posted January 21, 2008 I'm coding a program and I'm having trouble learning how to use the mail(); function while wanting to send mass emails from all emails within the dtabase, how would this be done? thanks Quote Link to comment https://forums.phpfreaks.com/topic/87033-mass-email/ Share on other sites More sharing options...
Lumio Posted January 21, 2008 Share Posted January 21, 2008 <?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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/87033-mass-email/#findComment-445071 Share on other sites More sharing options...
adam291086 Posted January 21, 2008 Share Posted January 21, 2008 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"; } Quote Link to comment https://forums.phpfreaks.com/topic/87033-mass-email/#findComment-445073 Share on other sites More sharing options...
Nhoj Posted January 21, 2008 Share Posted January 21, 2008 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.... Quote Link to comment https://forums.phpfreaks.com/topic/87033-mass-email/#findComment-445089 Share on other sites More sharing options...
hamza Posted January 21, 2008 Share Posted January 21, 2008 Please tell me one thing about the mail function Someone told me that it is not possible to send email from windows. AND MAIL FUNCTION REQUIRED A MAIL SERVER TO send an email please tell me about this thankx. Quote Link to comment https://forums.phpfreaks.com/topic/87033-mass-email/#findComment-445090 Share on other sites More sharing options...
Nhoj Posted January 21, 2008 Share Posted January 21, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/87033-mass-email/#findComment-445092 Share on other sites More sharing options...
Foser Posted January 21, 2008 Author Share Posted January 21, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/87033-mass-email/#findComment-445102 Share on other sites More sharing options...
Nhoj Posted January 21, 2008 Share Posted January 21, 2008 Pear mail & Pear Mail_Queue Package tutorial: http://pear.php.net/manual/en/package.mail.mail-queue.mail-queue.tutorial.php Works beautifully for mass e-mailing Quote Link to comment https://forums.phpfreaks.com/topic/87033-mass-email/#findComment-445103 Share on other sites More sharing options...
Foser Posted January 22, 2008 Author Share Posted January 22, 2008 the manual is comfusing me more than anything else, is there a place I can download one? and just change some variables? Quote Link to comment https://forums.phpfreaks.com/topic/87033-mass-email/#findComment-445994 Share on other sites More sharing options...
NikkiLoveGod Posted January 22, 2008 Share Posted January 22, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/87033-mass-email/#findComment-445999 Share on other sites More sharing options...
wrave Posted January 22, 2008 Share Posted January 22, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/87033-mass-email/#findComment-446010 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.