This topic is locked
[SOLVED]

 Send an email to selected users with personalized information !

9/11/2012 5:35:00 AM
PHPRunner General questions
N
netmedia59 author

Hello,
I want to send an email to selected users with personalized information such as their Passwords ...

I use PHPRunner 6.1

I have read the topic : http://xlinesoft.com/phprunner/docs/email_to_selected_users.htm
Here is my Server Code :
// Put your code here.

global $dal;

$dal_TableName = $dal->Table("actifs");

$email_list = "";

foreach(@$keys as $keyblock)

{

$arr=explode("&",refine($keyblock["Num"]));

if(count($arr)<1)

continue;

$arr2=array();

$arr2["Num"]=urldecode(@$arr[0]);

$where = KeyWhere($arr2);

$rstmp = $dal_TableName->Query($where,"");

$datatmp=db_fetch_array($rstmp );

if ($datatmp["ProEmail"])

$email_list.=$datatmp["ProEmail"].",";

}

if ($email_list)

$email_list = substr($email_list,0,-1);
//Send HTML email:

$from="contact@blabla.org";// your email, please change

$email=$email_list;

$msg="";

$msg.="<html>

<html>

<head>

<title>Confirmation</title>

</head>

<body>

<h2><font color=\"#000066\" face=\"Arial\">Confirmation</h2>

<p>
<p>Vos References</p>
."</p>
</body>

</html>

";

$subject="Confirmation";

$arr = runner_mail(array('bcc' => $email, 'subject' => $subject, 'htmlbody' => $msg, 'from'=>$from));// Note 'htmlbody' instead of 'html'!

$result["txt"] = "Emails Envoyes";
// if error happened print a message on the web page

if (!$arr["mailed"])

{

$errmsg = "Error happened:
";

$errmsg.= "File: " . $arr["errors"][0]["file"] . "
";

$errmsg.= "Line: " . $arr["errors"][0]["line"] . "
";

$errmsg.= "Description: " . $arr["errors"][0]["description"] . "
";

$result["txt"] = $errmsg;

}
With that code, the problem is that only the last data is sent, so it's not personalized at all
Thanks for your help
Olivier

Lille (FRANCE)

R
rencenji.denes 9/11/2012

Hi!
I use this sollution it is mutch more frendly <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=67706&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />
while($record = $button->getNextSelectedRecord())
{
$message = "Dear ".$record["FirstName"];

$message.= "Your password is ".$record["passwd"];
runner_mail(array('to' => $record["email"], 'subject' => "Greetings",
'body' => $message));
}
BR:

Dennis

N
netmedia59 author 9/11/2012

Hey Dennis,
Thanks for your message
I've done this in the server :

// Put your code here.

while($record = $button->getNextSelectedRecord())

{

$from="contact@forum-lille.org";// your email, please change

$subject="Confirmation d'Inscription";

$message = "Dear ".$record["Prenom"];

$message.= "Your password is ".$record["Nom"];

runner_mail(array('to' => $record["ProEmail"], 'subject' => $subject,'body' => $message));

}
But doesn't work ?
Thanks again
Olivier



Hi!
I use this sollution it is mutch more frendly <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=67708&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />
while($record = $button->getNextSelectedRecord())
{
$message = "Dear ".$record["FirstName"];

$message.= "Your password is ".$record["passwd"];
runner_mail(array('to' => $record["email"], 'subject' => "Greetings",
'body' => $message));
}
BR:

Dennis

R
rencenji.denes 9/12/2012



Hey Dennis,
Thanks for your message
I've done this in the server :

// Put your code here.

while($record = $button->getNextSelectedRecord())

{

$from="contact@forum-lille.org";// your email, please change

$subject="Confirmation d'Inscription";

$message = "Dear ".$record["Prenom"];

$message.= "Your password is ".$record["Nom"];

runner_mail(array('to' => $record["ProEmail"], 'subject' => $subject,'body' => $message));

}
But doesn't work ?
Thanks again
Olivier


HI Netmedia59!
Many of e-mail servers doesn't send e-mail if you don't set up the sender address.

As I see you didn't set this information inside the loop.
This is a working code (PHPR 5.3) from behind a custom button. A little bit different from you ask but the relevant thing is there.
Try to debug. If you are fail with this, when I travel home in the evening I send you a working getNextSelectedRecord() example code from 6.1


Php snipett to create a list (not public parts are truncated)

This is a List element where you can select one or more Item ( it's contains e-mail addresses,names and the relevant record ID) if you push the button the code loop trough the javascript element
//A list element to display a group of users
$gyujtok_sql = "SELECT nev_kod, EMAIL FROM xxxxx WHERE id IN (

SELECT id

FROM xxx.yyyy_zzz_vw

WHERE appcode='PHPRunner'

GROUP BY id)

union all

select data,data_owner from tablex where datatype='emailaddress' order by nev_kod";

$gyujtok_rs = CustomQuery($gyujtok_sql);

$gyujtok_data = db_fetch_array($gyujtok_rs);
echo "<SELECT id='s' name='s[]' size='5' multiple>";

while ($data_gyujtok = db_fetch_array($gyujtok_rs))

{

echo "<OPTION value='".$data_gyujtok["EMAIL"]."'>".$data_gyujtok["NEV_KOD"]."</OPTION>\n";

}

echo "</select>";

Custom button. If you pust the button send email all of the selected item
Client Before TAB
// Put your code here.

params["cim"]='';//e-mail address

params["nevek"]=''; //Names

params["azon"]=document.getElementById('value_AZON_1').value; //Database ID

var src = document.getElementById('s');

for(var count=0; count < src.options.length; count++) {

if(src.options[count].selected == true) {

var option = src.options[count];

params["cim"] = params["cim"]+option.value+',';

params["nevek"] = params["nevek"]+option.text+',';

}

}

//alert(params["cim"]);

// Uncomment the following line to prevent execution of "Server" and "Client After" events.

//return true;
Server TAB
global $conn;

$ret=runner_mail(array('to' => $params["cim"], 'subject' => "Teszt", 'body' => "Teszt", 'from'=>sender@host.hu));

if (!$ret["mailed"])

{

$result["txt"] = "Hiba történt";//Error occured

$result["txt"] .= "Fájl: " . $ret["errors"][0]["file"] . "

";

$result["txt"] .= "Sor: " . $ret["errors"][0]["line"] . "

";

$result["txt"] .= "Leírás: " . $ret["errors"][0]["description"] . "

";

}

else

{

$sql = "Update xxx set addresses=addresses||'".$params["cim"]."' where id='".$params["azon"]."'";

db_exec($sql,$conn);

$result["txt"]="Messages sent succesfully!";

}
Client AFTER TAB

// Put your code here.

var message = result["txt"];

ctrl.setMessage(message);


BR:

Dennis

N
netmedia59 author 9/12/2012

Hey
Thanks for that answer

But it's too complicated for me !

Is there something easier ?

Thanks again
Olivier

R
rencenji.denes 9/12/2012



Hey
Thanks for that answer

But it's too complicated for me !

Is there something easier ?

Thanks again
Olivier


Hi Olivier!
I try to help you.

I will send you a simple project if you send me your table(s) whith sample data.

What kind of mail server do you have?
BR:
Dennisx

N
netmedia59 author 9/12/2012

Hey Dennis,
Thanks very much for your message and for helping !
Here is my base :

-- ----------------------------

-- Table structure for actifs

-- ----------------------------

DROP TABLE IF EXISTS actifs;

CREATE TABLE actifs (

Num int(11) NOT NULL auto_increment,

ID varchar(20) NOT NULL default '',

Nom varchar(40) default NULL,

Prenom varchar(40) default NULL,

Password varchar(10) default NULL,

ProEmail varchar(50) default '',

SalonID int(11) default NULL,

PRIMARY KEY (Num),

) ENGINE=InnoDB AUTO_INCREMENT=13383 DEFAULT CHARSET=latin1;
We'll keep in touch

Thanks again
Olivier
Lille(FRANCE)