This topic is locked

email wont send in 'Add Page'

4/2/2017 8:20:58 AM
PHPRunner General questions
S
shoppy author

Hi,
I have two Tables: Deelnemers(members) and Event.
I like to send the person an email when he adds an Event.

and one when he edits an existing event (of his own).
The emails are exactly the same but in the edit event it sends perfectly but not in the add event.

I use 'After record is updated' in edit event and 'After record added' in the add event

What am I missing?



ini_set('SMTP','smtp.myserver.nl');

$html = true;
// variables

$to = $values['Email'];

$from = "info@mymail.nl";

$website_naam = 'Kostuumavond';
// Bericht

$subject = "Je wijziging";
$message = 'Dear '. $values[Achternaam] . ',' . "<br />" . "<br />";

$message .= 'Thanks.' . "<br />" . "<br />";

$message .= 'Regards,' . "<br />";

$message .= 'Administration' . "<br />" . "<br />";

$message .= 'John';
//Headers

$headers = 'From: ' . $website_naam . ' <' . $from . '>' . PHP_EOL;

$headers .= 'X-Mailer: PHP/' . phpversion() . PHP_EOL;

$headers .= 'X-Priority: Normal' . PHP_EOL;

$headers .= ($html) ? 'MIME-Version: 1.0' . PHP_EOL : '';

$headers .= ($html) ? 'Content-type: text/html; charset=iso-8859-1' . PHP_EOL : '';


// Send the message

mail($to, $subject, $message, $headers);
//********** Redirect to another page ************

header("Location: Event_list.php");

exit();


The table 'Deelnemers' contains the 'Achternaam' and the Email fields but I did an inner join of the two tables.

romaldus 4/2/2017

you don't have to define SMTP Address manually. Use PHPRunner built in Email Settings feature to define SMTP Address:

https://xlinesoft.co...in_settings.htm
Correct Code :


$email=$values["Email"];

$from="info@mymail.nl";

$fromName="John";

$subject="Je wijziging";

$message="Dear <b>".$values["Achternaam"]."</b>, \n



Thanks. \n



Regards \n



Administrator \n



<b>John</b>";
runner_mail(array('to' => $email, 'cc' => 'sample_address@yahoo.com', 'bcc' => 'sample_address@gmail.com','from' => $from, 'fromName'=> $fromName, 'subject' => $subject, 'htmlbody' =>$message))
romaldus 4/2/2017
S
shoppy author 4/3/2017



Runner mail function:

https://xlinesoft.com/phprunner/docs/runner_mail_function.htm


Hi Romaldus,
Thanks for your help.
But the problem stays.

In the edit event it sends the email perfectly with the $values I gave like 'Email' and 'Achternaam'.

But in de add event it does not. It just sends the mail without the $values to the fixed cc address.

I use after record added in the add event.

Sergey Kornilov admin 4/3/2017

Make sure your $values array is populated properly. Remove redirect and try to print the contents of $values array on the page. You must be doing something different in AfterAdd event or you doing something else in BeforeAdd event and not telling us what exactly.
To print contents of $values array use the following:

print_r($values);
S
shoppy author 4/3/2017



Make sure your $values array is populated properly. Remove redirect and try to print the contents of $values array on the page. You must be doing something different in AfterAdd event or you doing something else in BeforeAdd event and not telling us what exactly.
To print contents of $values array use the following:

print_r($values);




Hi Sergey,
All the Add Page Events are empty, just the After record added contains the code I published here before.

That code is exactly the same as the one in After record updated in the Edit page Event.
When I print the ($values) it just prints the ones in the "Event" table but not the ones in the "Deelnemers" table.

The Email value is in the Deelnemers table(just like the Achternaam value) so therefore it does not send the email.

They both don't show up with the print_r($values); code.

romaldus 4/3/2017



Hi Sergey,
All the Add Page Events are empty, just the After record added contains the code I published here before.

That code is exactly the same as the one in After record updated in the Edit page Event.
When I print the ($values) it just prints the ones in the "Event" table but not the ones in the "Deelnemers" table.

The Email value is in the Deelnemers table(just like the Achternaam value) so therefore it does not send the email.

They both don't show up with the print_r($values); code.


$values can only used to access fields on current table ("event" table in your case). If you want to access field values from other table ("deelnemers" table), you need to perform a custom sql query, save the result in session variable, and than add the session variable to your email

L
laonian 4/3/2017

You have a syntax error:
$values[Achternaam] should be $values["Achternaam"].

romaldus 4/3/2017

Or you can try something like this:

in "EVENT" table add page > before process, perform a custom query



$sql = "SELECT email AS mail FROM eelnemers WHERE any_field = 'any_value'"; //change any field and any value with actual field and value in your DB

$rs = CustomQuery($sql);

$data = db_fetch_array($rs);

$_SESSION["mail"] = $data["mail"];


in email code, change



$to = $values['Email'];


into



$to = $_SESSION["mail"];
S
shoppy author 4/4/2017

Just can't get it to work. Tried all the options you guy's gave me but nothing works.

So I changed it all to where I began and uploaded it al to the demo account.

Hope that Sergey's team me can help with this.
John

S
shoppy author 4/5/2017

Don't I need to call the Email field value from the Deelnemers table first so I can use it in the Event table?
I tried this but keep getting errors.
Can someone help me with the right code please?

romaldus 4/5/2017

can you upload a sample project file with database?

S
shoppy author 4/5/2017



can you upload a sample project file with database?


And did.