[development] Mail script problem: please help

Jamie Holly hovercrafter at earthlink.net
Sat Feb 13 16:51:10 UTC 2010


You're overwriting the $user variable since this script is running in 
the global namespace:


$user= $_GET['u'];

$user is populated with the user object on bootstrap and now you're 
changing it. That's your problem. To prevent conflicts I would wrap 
everything below:

         drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

into a function and just call that.

Jamie Holly
http://www.intoxination.net
http://www.hollyit.net


On 2/13/2010 10:52 AM, Dayton Perkins wrote:
> I am using Mime Mail to send mails to users who are opted in to a 
> users mailing list for a certain user role. I had written a similar 
> script for another site, looping through email addresses and invoking 
> mimemail() for each. Unfortunately though I pumped up the memory 
> limit, that script white screened ( haven't checked in too much detail 
> as the "client" is a non-payer), though the script did send out the mails.
>
> So for this project, I decided to class it up a bit using jQuery to 
> loop through sending $get requests to the server and load in a 
> "loading" graphic whilst waiting for a response for each mail in turn. 
> I put my mailing script in the docroot since putting it in my module 
> resulted in path errors. Everything works, including sending the 
> emails, loading in the loading graphic per email and then a sent 
> message, writing to the database, etc.  EXCEPT for 2 things.
> When I open the script in a browser, I get the following notices:
>
> *Notice*: Trying to get property of non-object in 
> */home/content/t/o/n/tonebari/html/modules/dblog/dblog.module* on line 
> *135*
> *Notice*: Trying to get property of non-object in 
> */home/content/t/o/n/tonebari/html/includes/database.mysqli.inc* on 
> line *102*
> *Notice*: Trying to get property of non-object in 
> */home/content/t/o/n/tonebari/html/modules/dblog/dblog.module* on line 
> *135*
> *Notice*: Trying to get property of non-object in 
> */home/content/t/o/n/tonebari/html/includes/database.mysqli.inc* on 
> line *102*
> *Notice*: Trying to get property of non-object in 
> */home/content/t/o/n/tonebari/html/modules/dblog/dblog.module* on line 
> *135*
> *Notice*: Trying to get property of non-object in 
> */home/content/t/o/n/tonebari/html/includes/database.mysqli.inc* on 
> line *102*
> *Notice*: Trying to get property of non-object in 
> */home/content/t/o/n/tonebari/html/modules/dblog/dblog.module* on line 
> *135*
> *Notice*: Trying to get property of non-object in 
> */home/content/t/o/n/tonebari/html/includes/database.mysqli.inc* on 
> line *102
>
>
> Additionally, *when I run the AJAX page, it sends the emails, writes 
> the data and everything looks dandy, but when I navigate to another 
> page I find I have been logged out! :-) I do see the first notice 
> above is inside dblog_watchdog() Seems to me that the browser isn't 
> sending cookies? I added global $user; print_r($user); right after the 
> call to drupal_bootstrap, (after re-logging ;-) )and I see that I my 
> user data is present.
> help? *
>
> *here's the mailer script
> <?php
> error_reporting(E_ALL);
> require_once './includes/bootstrap.inc';
> drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
> $sender = 'no-reply at example.com';
> $last = $_GET['l'];
> $cid = $_GET['c'];
> $user= $_GET['u'];
> if($user==0){ // not a user || no uid ;These emails are added to the 
> database another way...
>     $recipient = $_GET['e'];
>     $mail = $recipient;
> } else {
>      $recipient = get_user($user); // This gets the user object I also 
> tried just using global $user and $user->mail
>      $mail = $recipient->mail;
> }
> if(!isset($_SESSION['mailer-errors'])) { $_SESSION['mailer-errors']=0; }
> $subject = $_SESSION['subject'];
> $code=randStrng();
> $optLink = '<p>'.l('Opt out of these emails', 
> 'http://example.com/center/opt', array('query' => 
> 'cid='.$cid.'&code='.$code.'&mail='.$mail)).'</p>';
> $body = $_SESSION['body'].$optLink;
> if($sent = mimemail($sender, $recipient, $subject, $body)) {
>     write_promo_data($user, $recipient, $cid,  $code);
>     echo 1;
> } else {
>     echo 0;
>     $_SESSION['mailer-errors'] ++;
> }
> if($last ==1) {
>     if($_SESSION['mailer-errors']==0) {
>         unset($_SESSION['send']);
>         unset($_SESSION['subject']);
>         unset($_SESSION['body']);
>         unset($_SESSION['created']);
>     }
>     unset($_SESSION['mailer-errors']);
> }
> -- 
> /Kindest regards,/ *Dayton Perkins*
> Good News Design
> Intelligent Web Programming for Business
> 3611 Butternut Drive, Suite 40
> Holland MI 49424
> 616-399-5617
> http://goodnewsdesign.com
> Signature <http://goodnewsdesign.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20100213/4bf3fb7d/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 20888 bytes
Desc: not available
Url : http://lists.drupal.org/pipermail/development/attachments/20100213/4bf3fb7d/attachment-0001.gif 


More information about the development mailing list