Jump to content

function help !!


devofash

Recommended Posts

hello ppl got a question........ its quite silly one too *embarassed*

am trying to send an email after a query is updated..... but am getting an error saying :

Warning: mail() [function.mail]: SMTP server response: 554 Error: no valid recipients in C:\Program Files\xampp\htdocs\project\pending_job.php on line 131


here's the code below...... i think i need to pass $email into inform_user() but dont know how to ??

also can anyone suggest a better way of doing this..... it seems to me that i'm doing it the long way !!


[code]
     function pending()
     {
             // some stuff
     }

        function update()
        {
            // update query    
         }

     function inform_user()
     {
      
        mail($email, $subject, $message,
          "From: ORS Webmaster<me@domain.com>\n
          X-Mailer: PHP/" . phpversion());
     }
[/code]
Link to comment
Share on other sites

It depends, you can use something like this:

[code]function inform_user($email)
{
// code goes here
}[/code]

Or this:

[code]function inform_user()
{
   global $email;
}[/code]

For further information, look for "Variable Scope" in the Manual.
Link to comment
Share on other sites

Well, you should make pending() return $email... Something like this:

[code]function pending()
{
// do something

return $email;
}

function inform_user()
{
   global $email;
// do something
}

// calling the functions:

$email = pending();
inform_user();[/code]
Link to comment
Share on other sites

keep the same format as above,
only put the inform function above the update function,

also make the inform_user function ask for an email variable by calling...

function inform_user($email){ ...
instead of
function inform_user(){...

and then in function update simply call an email variable and pass it by calling inform_user($email);
Link to comment
Share on other sites

ok so this is what i've done so far .... it sorta works..... here's the code
[code]
<?
     $link = $_GET['link'];
     if($link == approve)
     {
       echo approve();
     }

     function pending()
     {
       // some stuff

        <td> <a href = \"?page=pending_job&link=approve&jobID=$jobID\">
       Approve </a></td>
       return $email;
     }

     function inform_user($email)
     {
       global $email;

          $subject = "blah";
          $message="blah";

       mail($email, $subject, $message,
          "From: ORS Webmaster<me@somedomain.com>\n
           X-Mailer: PHP/" . phpversion());
           echo "Mail has been sent";
     }

     function approve()
     {
       global $email;
           // update record
       if($result)
       {
         echo $email;
         inform_user($email);
       }
     }

     $email = pending();
     inform_user($email);  
?>
[/code]

i want it to send email to a person who's record is updated, after i press the approve link (thts when the record gets updated)

right now it just send an email to the last entry every time page is refreshed.
Link to comment
Share on other sites

easiest way from wat i can see is parse $email into the link field, so add [b]&email=$email[/b] in the link...
assuming the rows are being parsed thru a 'while' each link shuld have a different email value,

when doing a check for $link==approve,
set $email = $_GET['email']
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.