Call functions from external file

hi all

I want to apply 2 email functions to the two button in “order.php” but i dont want to write those functions code in order.php

So if i create a external file “mail.php” and write those functions in that file and call those functions in “order.php” through


require_once("email.php");

then will those functions work or not ?

and second question i want to know that is it fine to call “config.php” in both order.php and email.php

vineet

You would generally want the functions in email.php to be oblivious to which config.php file you include, but in principle you are correct in your assumptions.

Why don’t you try it and test everything get wired up together as you would expect?

Here is something to get you started:

config.php


<?php
$my_email_address="myemail.gmail.com";
?>

email.php


<?php
function sendEmail($address){
  return "<p>I am now sending an email to $address</p>";
}
?>

order.php


<?php
include_once 'config.php';
include_once 'email.php';

echo '<h3>wow, I got an order!</h3>';

$clients_email_address = $_GET['client'];

sendEmail($my_email_address);
sendEmail($clients_email_address);

?>

For the time being to prove the theory put all the files in the same folder and test with:

order.php?client=theiremail.gmail.com

and if everything is wired up correctly, ie order will accept includes from the same folder, it should come out with the proof you need.

The example above is:
-Untested
-Insecure
-Not robust
-Pre-supposes that includes will be included from the same folder as your calling script (order.php).

but should answer your question, else reply with errors or further questions.