This topic is locked
[SOLVED]

 How to send email to user with new record

2/11/2014 9:39:10 AM
PHPRunner General questions
A
Abul author

I have user and order tables. User table has user_email field and order table has order_no field. When user submit an order by order_add page then order_no field in the order table will be auto-inserted value by after add event on order page. What I wish my app should automatically shoot email to the user with new order_no that generated for his new submitted order. How can I accomplish this? I see PHPR email events only send email with new data to hard coded email address. Thanks in advance.

M
macalister 2/13/2014

Hi.
You can send an email with your order_no to the costumer in after record added event order. I supposed that order and user are related



//get the costumer's email based on order data.
$datauser = "select email from user where user.userdId = '".$values["userIdorder"]."'";

$dataEmail = db_query($datauser,$conn);

$emailUser = db_fetch_array($dataEmail);
//********** Send email ************
$email= $emailUser["email"];

$from="yourcompany@company.com";

$msg="New order "'.$values["order_no"].'"";

$subject="any subject";
foreach($values as $field=>$value)

{

if(!IsBinaryType(GetFieldType($field)))

$msg.= $field." : ".$value."\r\n";

}



$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

if(!$ret["mailed"]){

echo $ret["message"];



}

return false;

}
A
Abul author 2/19/2014



Hi.
You can send an email with your order_no to the costumer in after record added event order. I supposed that order and user are related



//get the costumer's email based on order data.
$datauser = "select email from user where user.userdId = '".$values["userIdorder"]."'";

$dataEmail = db_query($datauser,$conn);

$emailUser = db_fetch_array($dataEmail);
//********** Send email ************
$email= $emailUser["email"];

$from="yourcompany@company.com";

$msg="New order "'.$values["order_no"].'"";

$subject="any subject";
foreach($values as $field=>$value)

{

if(!IsBinaryType(GetFieldType($field)))

$msg.= $field." : ".$value."\r\n";

}
$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

if(!$ret["mailed"]){

echo $ret["message"];
}

return false;

}




It does not works. I have Before event to shoot email to Admin on the same page. I just use this code on After record added event on the same page. Admin get email, but user doesn't. Moreover the form get hang with error msg:

Error type 2

Error description mysqli_query() expects parameter 1 to be mysqli, string given

URL localhost/test1/ord_add.php?ferror=1&fly=1&

Error file C:\xampp\htdocs\test1\include\dbconnection.my.mysqli.php

Error line 43

SQL query


Could you please help me again. Thanks.

A
Anapolis 2/20/2014

This line in the given example looks slightly wrong to me --
as an example I have a working Email script in "After Record Added" events that uses a current form variable in a where statement like this --
[size="3"][font="Tahoma"]$strSQLInsert2 = "UPDATE hb_vb SET created= NOW() where sched_id= '".$values["sched_id"]."';[/size]
according to my own working script example then this line should read:
[size="4"]."';
It is impossible in the browser spacing to see it clearly but on the left side you have a single apostrophe sign ' followed by a double apostrophe or quote mark "
and on the right side that is a double apostrophe or quote " followed by a single apostrophe '
the double apostrophe or quote marks are Wrapped by single apostrophe marks.[/size]
[size="4"]HOWEVER, keep in mind that Macalister gave you a generic example when it comes to the names for the Actual fields themselves.
You have to modify this script to match your own Field names to make it work. And in his example he has a small "error" where he references $values["userIdorder"].
If the field of the new order is also in the "user" table then it must be written $values["user.Idorder"]." ... put a period between the table name . field name, as he did in "user.userId".
Make the example MacAlister gave you match your own table and field names.[/size]

A
Abul author 2/20/2014



This line in the given example looks slightly wrong to me --
as an example I have a working Email script in "After Record Added" events that uses a current form variable in a where statement like this --
[size="3"][font="Tahoma"]$strSQLInsert2 = "UPDATE hb_vb SET created= NOW() where sched_id= '".$values["sched_id"]."';[/size]
according to my own working script example then this line should read:
[size="4"]."';
It is impossible in the browser spacing to see it clearly but on the left side you have a single apostrophe sign ' followed by a double apostrophe or quote mark "
and on the right side that is a double apostrophe or quote " followed by a single apostrophe '
the double apostrophe or quote marks are Wrapped by single apostrophe marks.[/size]
[size="4"]HOWEVER, keep in mind that Macalister gave you a generic example when it comes to the names for the Actual fields themselves.
You have to modify this script to match your own Field names to make it work. And in his example he has a small "error" where he references $values["userIdorder"].
If the field of the new order is also in the "user" table then it must be written $values["user.Idorder"]." ... put a period between the table name . field name, as he did in "user.userId".
Make the example MacAlister gave you match your own table and field names.[/size]


Finally I solved.

What I did:

  1. put in After Successful Login event

$_SESSION["Email"]=$data["email"];


2. Add before record added event to shoot email to user who submit new order with new order number

$email=$_SESSION["Email"];

$from="no-reply@mycompany.com";

$msg="";

$subject="New Test Order Submitted";



$msg.= "Order No: ".$values["ordno"]."\r\n";


$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

if(!$ret["mailed"])

echo $ret["message"];


3. Add After record added event to shoot same new order info to the Admin

$email="admin@mycompany.com";

$from="noreply@system.com";

$msg="";

$subject="New Order Submitted";



$msg.= "New Order number: ".$values["ordno"]."\r\n";


$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

if(!$ret["mailed"])

echo $ret["message"];


Thats it and it works for me. Thanks to all of you guys. if you find any error in those code please let me know. Thanks again.

A
Anapolis 2/20/2014



Finally I solved.

What I did:

  1. put in After Successful Login event

$_SESSION["Email"]=$data["email"];


2. Add before record added event to shoot email to user who submit new order with new order number

$email=$_SESSION["Email"];

$from="no-reply@mycompany.com";

$msg="";

$subject="New Test Order Submitted";
$msg.= "Order No: ".$values["ordno"]."\r\n";
$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

if(!$ret["mailed"])

echo $ret["message"];


3. Add After record added event to shoot same new order info to the Admin

$email="admin@mycompany.com";

$from="noreply@system.com";

$msg="";

$subject="New Order Submitted";
$msg.= "New Order number: ".$values["ordno"]."\r\n";
$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

if(!$ret["mailed"])

echo $ret["message"];


Thats it and it works for me. Thanks to all of you guys. if you find any error in those code please let me know. Thanks again.


Beautiful! I will keep your example on hand in case I ever need this solution.
Thanks!