This topic is locked

Send An Email With New Data

1/26/2013 12:08:14 PM
PHPRunner General questions
T
tabarin author

I would like to get some tips on how to modify the default code for sending email on creation of new data. What I have in mind is sending an email with selected fields of the new record rather than the send all fields as an array as is the case with default coding option. I have tried adding accessing specific field value using $values["FieldName"], but somehow end up looping the fields' values in the email (without selectively getting the desired fields).
Here is the code as it is for assistance:
//** Send email with new data ****
$email="somebody@gmail.com";

$from="someone@gmail.com";

$msg="";

$subject="A new record has been created !. Please log into view.";
foreach($values as $field=>$value)

{

if(!IsBinaryType($pageObject->pSet->getFieldType($field)))

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

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

}
//$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'htmlbody' => $msg, 'from'=>$from, 'charset' => 'UTF-8'));

$ret=runner_mail(array('to' => $email, 'cc' => 'someoneelse@gmail.com', 'subject' => $subject,'htmlbody' => $msg, 'from'=>$from, 'charset' => 'UTF-8'));
if(!$ret["mailed"])

echo $ret["message"];
// Place event code here.

// Use "Add Action" button to add code snippets.
// Place event code here.

// Use "Add Action" button to add code snippets.
Is there something that I am missing here?
Much thanks.

A
Andrew S 1/26/2013

Hi. I am also a newbie with software and still learning. However, I do something similar and this is the code I use in the After Record Added event i.e. When a customer places an order (Add Page)
There are probably better ways to do this but it works for me.
//** Send confirmation email with new data ****
$_SESSION["FullName"] = $values["order_name"];

$_SESSION["OrderID"] = $values["orderID"];

$_SESSION["Product"] = $values["order_product"];

$_SESSION["OrderTotal"] = $values["order_total"];

$_SESSION["OrderDelivery"] = $values["order_delivery"];
//email addresses to send email to (I have changed these rather than show real ones
$email = "someone@somewhere.co.uk,someoneelse@somewhereelse.co.uk";

$order_email = $values['order_email'];

$orderID = $values['orderID'];

$order_name = $values['order_name'];

$order_address1 = $values['order_address1'];

$order_address2 = $values['order_address2'];

$order_town = $values['order_town'];

$order_pcode = $values['order_pcode'];

$order_contact = $values['order_contact'];

$order_email = $values['order_email'];

$order_product = $values['order_product'];

$order_price = $values['order_price'];

$order_delivery = $values['order_delivery'];

$order_del_price = $values['order_del_price'];

$order_total = $values['order_total'];

$order_comment = $values['order_comment'];
// Provide link straight to the order (domain name changed here)
$orderlink = "http://www.domainname.co.uk/orders/Orders_view.php?editid1=";;

$orderlink = $orderlink . $values['orderID'];
// Provide link to edit the order (once again, domain name changed here)
$ordereditlink = "http://www.domainname.co.uk/orders/Orders_edit.php?editid1=";;

$ordereditlink = $ordereditlink . $values['orderID'];
// Provide link to invoice for the order
$orderinvoicelink = "http://www.domainname.co.uk/orders/Customer_Invoice_view.php?editid1=";;

$orderinvoicelink = $orderinvoicelink . $values['orderID'];

$order_price=number_format($order_price,2);

$order_total=number_format($order_total,2);

$order_del_price=number_format($order_del_price,2);
// The subject
$subject = "Order Number $orderID has been submitted";
// The message
$message = "Graham,\n\nA free range order has been placed via the website as follows:\n

Order Number : $orderID

Full name : $order_name

Address1 : $order_address1

Address2 : $order_address2

Town : $order_town

Postcode : $order_pcode

Email : $order_email

Telephone : $order_contact

Product Ordered : $order_product

Product Price : $order_price

Delivery Required : $order_delivery

Delivery Price : $order_del_price

Total Order Price : $order_total

Comments : $order_comment

View Order here : $orderlink

Edit Order here : $ordereditlink

Order Invoice here : $orderinvoicelink";
mail($email, $subject, $message, "From: graham@hanroxfarm.co.uk");
// Place event code here. Here I redirect to a custom confirmation page.

header("Location: confirm.php");

exit();

T
tabarin author 1/28/2013

Much thanks...let me try and will get back in case I need your help again.



Hi. I am also a newbie with software and still learning. However, I do something similar and this is the code I use in the After Record Added event i.e. When a customer places an order (Add Page)
There are probably better ways to do this but it works for me.
//** Send confirmation email with new data ****
$_SESSION["FullName"] = $values["order_name"];

$_SESSION["OrderID"] = $values["orderID"];

$_SESSION["Product"] = $values["order_product"];

$_SESSION["OrderTotal"] = $values["order_total"];

$_SESSION["OrderDelivery"] = $values["order_delivery"];
//email addresses to send email to (I have changed these rather than show real ones
$email = "someone@somewhere.co.uk,someoneelse@somewhereelse.co.uk";

$order_email = $values['order_email'];

$orderID = $values['orderID'];

$order_name = $values['order_name'];

$order_address1 = $values['order_address1'];

$order_address2 = $values['order_address2'];

$order_town = $values['order_town'];

$order_pcode = $values['order_pcode'];

$order_contact = $values['order_contact'];

$order_email = $values['order_email'];

$order_product = $values['order_product'];

$order_price = $values['order_price'];

$order_delivery = $values['order_delivery'];

$order_del_price = $values['order_del_price'];

$order_total = $values['order_total'];

$order_comment = $values['order_comment'];
// Provide link straight to the order (domain name changed here)
$orderlink = "http://www.domainname.co.uk/orders/Orders_view.php?editid1=";;

$orderlink = $orderlink . $values['orderID'];
// Provide link to edit the order (once again, domain name changed here)
$ordereditlink = "http://www.domainname.co.uk/orders/Orders_edit.php?editid1=";;

$ordereditlink = $ordereditlink . $values['orderID'];
// Provide link to invoice for the order
$orderinvoicelink = "http://www.domainname.co.uk/orders/Customer_Invoice_view.php?editid1=";;

$orderinvoicelink = $orderinvoicelink . $values['orderID'];

$order_price=number_format($order_price,2);

$order_total=number_format($order_total,2);

$order_del_price=number_format($order_del_price,2);
// The subject
$subject = "Order Number $orderID has been submitted";
// The message
$message = "Graham,\n\nA free range order has been placed via the website as follows:\n

Order Number : $orderID

Full name : $order_name

Address1 : $order_address1

Address2 : $order_address2

Town : $order_town

Postcode : $order_pcode

Email : $order_email

Telephone : $order_contact

Product Ordered : $order_product

Product Price : $order_price

Delivery Required : $order_delivery

Delivery Price : $order_del_price

Total Order Price : $order_total

Comments : $order_comment

View Order here : $orderlink

Edit Order here : $ordereditlink

Order Invoice here : $orderinvoicelink";
mail($email, $subject, $message, "From: graham@hanroxfarm.co.uk");
// Place event code here. Here I redirect to a custom confirmation page.

header("Location: confirm.php");

exit();