This topic is locked

Sending mails to registered users that opt-in

3/22/2007 07:11:43
PHPRunner General questions
M
mmponline author

I have a need to send e-mails to all users in my login table that ticked the field Cancellations field as "Yes". This e-mail needs to be sent when a new record is added by admin. I got this code from support, but it is suddenly not working anymore- used to sent e-mails without a problem. The record is saved and returns to the list page (as setup as event on after record added), but no mails are sent out.
Can anyone maybe see an error in the code?

function BeforeAdd(&$values)

{

global $conn;

$all_emails="";

$strSQL = "select Email from Login where Available='Yes'";

$rs = db_query($strSQL,$conn);

while ($data = db_fetch_array($rs))

$all_emails .= $data["Email"].", ";

$all_emails = substr($all_emails,0,strlen($all_emails)-2);

$message="The following rentals are available. Please book at our office.\r\n";

$subject="Rental Availability:";

foreach($values as $field=>$value)

$message.= $field." : ".$value."\r\n";
mail($all_emails, "$subject", "$message");
return true;

}


Have newest version 218 of PHPRunner installed.

M
mmponline author 3/22/2007

Got this sorted out:

function BeforeAdd(&$values)

{
// Parameters:

// $values - Array object.

// Each field on the Add form represented as 'Field name'-'Field value' pair
//********** Send email with new data ************

global $conn;

$all_emails="";

$mailfrom1 = "mail@mail.com";

$strSQL = "select Email from Login where Available='Yes'";

$rs = db_query($strSQL,$conn);

while ($data = db_fetch_array($rs))

$all_emails .= $data["Email"].", ";

$all_emails = substr($all_emails,0,strlen($all_emails)-2);

$email="mmp@mmponline.co.za";

$message="The following rentals are available. Please book at our office.\r\n";

$subject="Rental Availability:";
$message.= "From : ".$values["c_from"]."\r";

$message.= "To : ".$values["c_to"]."\r";

$message.= "Croft Number : ".$values["c_croftid"]."\r";

$message.= "Rate : ".$values["c_rate"]."\r";

$message.= "Beds : ".$values["c_beds"]."\r";

$message.= "Contact and Details :\r ".$values["c_admin"]."\r";
mail($all_emails, $subject, $message, 'From: '.$mailfrom1);
return true;
// return true if you like to proceed with adding new record

// return false in other case
}
M
mmponline author 3/23/2007

This script only works if e-mails are sent to a few addresses. Once the addresses becomes more, it sends nothing at all.
Why would this be? and how can it be sorted out?