Calling a Function inside the SendMail

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Syl

    Calling a Function inside the SendMail

    Hi Group - I have a function to send an email to a client after they
    have successfully submitted a form on my site. I have a 2nd function
    that prints their input to the browser as a confirmation.

    I'd like to be able to include that print function inside my mail
    message like this :

    function sendToClient($e mail) {
    $subject = 'Confirmation';
    -----> $message = printConfirm($l ang); <----
    $headers = 'MIME-Version: 1.0' . "\r\n";
    <snip>, etc
    mail($to, $subject, $message, $headers);
    }

    This way I don't have to duplicate the output. The confirmation will
    get printed to the browser AND the exact same content will be emailed.

    When I executer this the email is blank.

    Any expert ideas out there ?

  • Martyr2

    #2
    Re: Calling a Function inside the SendMail

    Remember that variables inside a function like this are treated as
    local variables unless specified by the "global" keyword. Since I don't
    see you defining the variable $lang in your function, it is empty and
    thus no message is returned.

    Fix - Either define the $lang as "global" in the function (that is if
    $lang is defined outside the function) or the better way is to be sure
    to pass the $lang variable as a parameter to this function.

    Here is a resource link to what I am talking about... it is a variable
    scoping issue I am guessing from what I see there.



    Hope this helps :)

    Comment

    • Syl

      #3
      Re: Calling a Function inside the SendMail

      Hi Martry2 - thanks for going over this in detail.

      The lang variable *is* actually global in scope, but there are other
      parameters that are required that I did NOT make global - so this
      should be the resolve!

      thanks again!

      Comment

      Working...