Hello, i wud like to send different data(1st store in my db) nd then send, to different users in my database with mail() function, can anyone tell me how can i achieve this? Example- there are 60 registered members in my site, so for each member i wud like to send a unique message, but all at once, so can anyone help me ? Thank u..
Php mail() code in this situation
Started on the old forum in October 2013 · view the original in the archive · old links redirect here
Hi. 🙂
Like this, just change table names and maybe write a form to add message.
$emails = array();
$select = mysql_query('SELECT `email` FROM `users`');
while ($sel = mysql_fetch_array($select)) {
$emails[] = $sel[0];
}
foreach ($emails as $email) {
$subject = 'Subject...';
$message = 'Message...';
$header = 'MIME-Version: 1.0'.PHP_EOL;
$header .= 'Content-type: text/html; charset=utf-8'.PHP_EOL;
$header .= 'From: mailing@mail.com';
@mail($email, $subject, $message, $header);
echo 'Sent!';
}
i would recommend making sure the server your on. allows email sending and doesnt limit you to how many emails you send in a certain period of time. as with a function such as this it could be classed as mass mailing. (email bombing) even though going to many different email addresses. its a very quick way to getting your site/server account suspended.
be careful and make sure your allowed to do these things on server. goodluck and happy coding 🙂
Ghost wrote: i would recommend making sure the server your on. allows email sending and doesnt limit you to how many emails you send in a certain period of time. as with a function such as this it could be classed as mass mailing. (email bombing) even though going to many different email addresses. its a very quick way to getting your site/server account suspended.
be careful and make sure your allowed to do these things on server. goodluck and happy coding :)
Thanks alot bro.. 🙂
Added after 2 minutes:
arnage, thanks bro, but i want to store the message(s) in database first and send to all.. Example, i wil store user1 msg as 'hello' and user2 msg as 'hi' user3 msg as 'welco' etc.., and i want to send email to all three at same time wid the messages(as body) assosiated wid each user in database, now can u help me?
Ajayme wrote: Thanks alot bro.. 🙂
Added after 2 minutes:
arnage, thanks bro, but i want to store the message(s) in database first and send to all.. Example, i wil store user1 msg as 'hello' and user2 msg as 'hi' user3 msg as 'welco' etc.., and i want to send email to all three at same time wid the messages(as body) assosiated wid each user in database, now can u help me?
Build a submit form with 3 fields for user 1 2 3 (or a drop down to select the user and set message) then use mysql insert to store messages with email@ as id , after that create a link or php action to execute the code from bottom .
Mysql table "messagelist" with 2 fields
as id [email] => "demo@mailer.com" message=> "Hellow there how are you"
<?php
$emails = array();
$select = mysql_query('SELECT `email` FROM `users`');
while ($sel = mysql_fetch_array($select)) {
$emails[] = $sel[0];
}
foreach ($emails as $email) {
$select = mysql_fetch_array(mysql_query('SELECT message FROM messagelist WHERE email="'.$email.'" '));
if(empty($select[0])){
// if is no message stored for email@
$selectmessage="Hellow there";
}
else{
// message from database for email@
$selectmessage=$select[0];
}
$subject = 'Subject...';
$message = $selectmessage ;
$header = 'MIME-Version: 1.0'.PHP_EOL;
$header .= 'Content-type: text/html; charset=utf-8'.PHP_EOL;
$header .= 'From: mailing@mail.com';
@mail($email, $subject, $message, $header);
echo 'Sent!';
}
?>
This is ten percent luck, twenty percent skill Fifteen percent concentrated power of will Five percent pleasure, fifty percent pain 😂And a hundred percent reason to remember the name!