...

View Full Version : mail($to, $subject, $message, $headers)



Tulungo
01-22-2010, 06:04 PM
Another problem.
I'm creating a .php auto sender mail to diferent persons in there Birthday.

here is the query:

$data =date("m", time());
$data1=date("d",time());


mysql_select_db( $db, $link ) or die ( "Couldn't open $db: ".mysql_error() );
$result = mysql_query( "SELECT Nome, Email FROM funcionarios where extract(day from Data_de_Nascimento)='$data1' and extract(month from Data_de_Nascimento)='$data' order by Data_de_Nascimento" );

then i make a while to capture the mail and the name:

while ( $row = mysql_fetch_array( $result ) )
{
$to .= $row[Email] . ',';
rtrim($to, ',');
$na .= $row[Nome] . ',';
rtrim($na, ',');
}



then i try to send it like this:

$sub="Feliz aniversario";
ini_set('SMTP', 'mail.clix.pt');
$subject = "$sub";
$message = "A fastforward $na ................................ Feliz aniversario";
$headers = 'From: bitlo@clix.pt' . "\r\n" .
'Reply-To: bitlo@clix.pt' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

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

its sends to all the mail capture in the database, the problem is that in all mails it sends all the names, and i nedd to put in the mail the equal name.

remind the names are capture from the database.

Can someone Help.

Fou-Lu
01-22-2010, 06:16 PM
Two options. The first is to use blind carbons for each person on the list, and just send the one email to yourself with the blinds. The other option is to send a single mail for each entry in you're database. This approach is... not exactly what you want, depending on you're records size.
The best approach is to cron a job to create a temporary table that contains all the people who need to be emailed. Then, cron another script to go through this table every minute or so, and extract say 10 names at a time. Then email them. Then delete them. This should keep you're load under control.

Tulungo
01-22-2010, 06:25 PM
Ok thanks for reply.
But that is not the issue, i need to put in the message the right name.
Now it send the mails to the people o makes birthday, supose it make 50 people, it sends to the 50 people but in the message it go's 50 name, and i need to put only one name to one mail.
Im trying with for each but i dont get it right

tomws
01-22-2010, 06:46 PM
Well, show the foreach to get help with it.

Dormilich
01-23-2010, 12:02 PM
But that is not the issue, i need to put in the message the right name.
Now it send the mails to the people o makes birthday, supose it make 50 people, it sends to the 50 people but in the message it go's 50 name, and i need to put only one name to one mail.

the SwiftMailer (http://swiftmailer.org/) email library has a plugin (http://swiftmailer.org/docs/decorator-plugin) that allows you to send personalized emails in a batch.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum