Create new tab with specified url and new tab with sound when new email

My recommendation would be to use ajax and call a fetchMail at an interval rather than refresh the entire page.

That code needs to be between script tags to work. Why it would work in php tags is curious. Yes, it is a click function.

Good the sounds work now…

The other script is exactly that. As I have said many times, it is JS or JQuery. This means that it runs on
the CLIENT-SIDE which is in the browser. So, that means it should be in the HTML inside script tags…

The PHP side should add in an print command that displays a call to that script when needed if a new
email arrives. This call to the script should be inside the tag… Again something like this:

>

(Off the top of my head…) Now the click is so that you can make it a link as you first ask for. You can
change that by just making it a function. Something like this: (untested, just from memory…)
[php]

[/php]
This would be just a simple Javascript function similar to the JQuery version for the click function.
Note I added the _blank option on the section one. If you set up the alarm.php to open in a separate
window, you can add in a Javascript routine in that page to automatically close itself after a few seconds…

Hope that helps…

Oh, also, if you use that sound routine inside the display of the email, then you really do not need the
second page, do you?

Oh, also, if you use that sound routine inside the display of the email, then you really do not need the second page, do you?
[..] inside the display of the email [..]
What do you mean by that? The link from the content of the new email goes directly into the url of the new tab, so how would you integrate the sound if not in its own tab?

I created this code (hope I have followed all your instructions), and I use $ok to tell if a new email has been identified - and it does not display the two tabs when a new email arrives. Nor does it go to the $link url, if I remove the if-clause in the body tag:

[php]<body <?php if ($ok=="1"){echo "ONLOAD='open2pages();'";}?> >

<?php $ok=''; $imap = imap_open("{imap.one.com}","EMAIL", "PASSWORD"); if( $imap ) { $MC = imap_check($imap); // Fetch an overview for all messages in INBOX $result = imap_fetch_overview($imap,"4200:{$MC->Nmsgs}",0); foreach ($result as $overview) { $nr = "{$overview->msgno}"; $seen = "{$overview->seen}"; if($seen == "0") { $text = imap_fetchbody($imap,$nr,1); $pos = strpos($text, "http");$http = substr($text, $pos);$end = strpos($http, '=');if ($end>0); else $end = strpos($http, " "); if ($end>0) { $link = substr($http, 0, $end);} else { $link = substr($http, 0); } $ok='1'; } } } ?> [/php]

However, it does open the two tabs every time the page is refreshed, if I remove the if-clause in the body tag, so that is a good thing :slight_smile:

Okay, first, I forgot you are opening a URL as one of the two tabs. So, to do it in one page, you would have
to embed the URL into a new page. More work than it is worth…

Now, when you remove the if clause, does it open the URL as it should? And, does the second tab play the
sound as it should? If they are both working, we are almost done with this puzzle…

SO, if you remove the if-clause, you are basically forcing the two pages to open. So, that is a great way to
test the results to make sure they look and sound good. But, this also tells you that your if-clause is bad in
some way.

To check, you would have to make sure that the $ok variable is actually being loaded by your email-check
routine. I am guessing that it is not loaded when a new email shows up…

By the way, you do not need the extra braces after the if clause. In PHP, they are assumed if only one
command follows after if… If (condition) echo “xxx”; Saves a couple chars…

So, you should echo the $ok variable to make sure it is filling inside your email-check routine. And, send
a test email so you can make sure it is working…

Lastly, a trick I use all the time for debugging is to VIEW-SOURCE of the page, in your case between the
refreshes to see if the code in the tag looks correct. Just RIGHT-CLICK on your page and view the
source. Look down to the body tag and see if it is well-formed.

Hope that helps…

I agree. Some puzzle this is!

Yes, it does open the two tabs and the sound is playing. However, the $link variable is not used in the one tab.

I have already tested this with a “new” email, loading $ok on new email, echoing $ok, placing the script different places, etc. The $ok variable becomes “1” when new email, but the rest is not activated.

Okay, that rules out a lot. Thanks!

Now, if you echo the $URL, and you take the output of it and paste it into the address of a new window,
does it actually show the correct URL page? If it does, then, it is the formatting of the IF-CLAUSE. If it does
NOT display the page, it could be that you are not adding in the server name in the URL or something else.

Let’s check those two first and I will look at the IF-CLAUSE more to see if I missed something…

Oh, and did you RIGHT-CLICK on the page and view the source to see if the ONLOAD clause looks correct?

Right-clicking on page shows this (with the if-clause in the body tag):
[php]

[/php]

And like this with the if-clause:

[php]

READER

[/php]

To me this looks fine.

Now if I set the $link to phphelp.com in the body tag, like this, the url-tab will be correct:

[php]<body <?php $link='http://www.phphelp.com'; echo "ONLOAD='open2pages();'";?> >

<?php $ok=''; echo $ok; $imap = imap_open("{imap.one.com}","---", "---"); if( $imap ) { $MC = imap_check($imap); // Fetch an overview for all messages in INBOX $result = imap_fetch_overview($imap,"4200:{$MC->Nmsgs}",0); foreach ($result as $overview) { $nr = "{$overview->msgno}"; $seen = "{$overview->seen}"; if($seen == "0") { $text = imap_fetchbody($imap,$nr,1); $pos = strpos($text, "http");$http = substr($text, $pos);$end = strpos($http, '=');if ($end>0); else $end = strpos($http, " "); if ($end>0) { $link = substr($http, 0, $end);} else { $link = substr($http, 0); } $ok='1'; } } } ?> [/php]

It will also be correct like this, if I set $link later on the page:

[php]<body <?php echo "ONLOAD='open2pages();'";?> >

<?php $link='http://www.phphelp.com'; $ok=''; echo $ok; $imap = imap_open("{imap.one.com}","---", "--"); if( $imap ) { $MC = imap_check($imap); // Fetch an overview for all messages in INBOX $result = imap_fetch_overview($imap,"4200:{$MC->Nmsgs}",0); foreach ($result as $overview) { $nr = "{$overview->msgno}"; $seen = "{$overview->seen}"; if($seen == "0") { $text = imap_fetchbody($imap,$nr,1); $pos = strpos($text, "http");$http = substr($text, $pos);$end = strpos($http, '=');if ($end>0); else $end = strpos($http, " "); if ($end>0) { $link = substr($http, 0, $end);} else { $link = substr($http, 0); } $ok='1'; } } } ?> [/php]

It will also work, if I mark an email as unread and set $link only if there is a new email. And the tab will be empty if no new email, once I refresh the page:

[php]<body <?php echo "ONLOAD='open2pages();'";?> >

<?php $ok=''; echo $ok; $imap = imap_open("{imap.one.com}","---", "---"); if( $imap ) { $MC = imap_check($imap); // Fetch an overview for all messages in INBOX $result = imap_fetch_overview($imap,"4200:{$MC->Nmsgs}",0); foreach ($result as $overview) { $nr = "{$overview->msgno}"; $seen = "{$overview->seen}"; if($seen == "0") { $text = imap_fetchbody($imap,$nr,1); $pos = strpos($text, "http");$http = substr($text, $pos);$end = strpos($http, '=');if ($end>0); else $end = strpos($http, " "); if ($end>0) { $link = substr($http, 0, $end);} else { $link = substr($http, 0); } $ok='1'; $link='http://www.phphelp.com'; } } } ?> [/php]

Yes, it must be the if-clause…

Of course WITHOUT the if-clause in the extract 2 when right-clicking…

Also, the $ok is not echoed as ‘1’ when a new email comes:

[php]<body <?php echo $ok;if ($ok=="1") echo "ONLOAD='open2pages();'";?> >[/php]

Neither like this:

[php]<body <?php echo $ok;if ($ok=="1") echo "ONLOAD='open2pages();'";?> >

<?php $ok='1';[/php]

Well, you solved it then? I mean, if you echo $ok when a new mail item shows up, then, the code used
to check for it is NOT setting the $ok variable correctly! So, backtrack to where the $ok variable is set and
check to find out why it is not setting it correctly.

It appears that the $URL and sound and javascript is all working correctly. It is just not knowing when a
new mail item is in. So, recheck that part and you should be all set…

No the if-clause in the body tag will not identify when $ok is set to 1. Even though it is set to 1 in the body tag itself.

Well, as you showed the test, it would not work, so you need to fix that for testing…
change:

> <?php $ok='1';

to something like:

<?PHP $ok=1; ?> >

You can’t set the value AFTER it is checked for… Your email-check code MUST be before the body tag if you
want it to check for new mail. Also, you should get rid of the extra space in the body tag. should
be Just so you don’t get errors when the site is validated by Google or W3…

No, it does not work:

[php]<?php $ok='5';echo $ok;?>

> [/php]

…Will echo 5, but only one time. And this echoes nothing:

[php]<?php $ok='5';?>

> [/php]

I think you can only have one “sentence” in the body tag, because this works I did as you said:

[php]

<?php $imap = imap_open("{imap.one.com}","--", "--"); if( $imap ) { $MC = imap_check($imap); // Fetch an overview for all messages in INBOX $result = imap_fetch_overview($imap,"4200:{$MC->Nmsgs}",0); foreach ($result as $overview) { $nr = "{$overview->msgno}"; $seen = "{$overview->seen}"; if($seen == "0") { $text = imap_fetchbody($imap,$nr,1); $pos = strpos($text, "http");$http = substr($text, $pos);$end = strpos($http, '=');if ($end>0); else $end = strpos($http, " "); if ($end>0) { $link = substr($http, 0, $end);} else { $link = substr($http, 0); } $ok='1'; $link='http://www.phphelp.com'; } } } ?> > [/php]

Which is good. However, when I do not set $link (and instead retrieve it from the new email), it will not work at all and no tabs appear:

[php][php]

<?php $imap = imap_open("{imap.one.com}","--", "--"); if( $imap ) { $MC = imap_check($imap); // Fetch an overview for all messages in INBOX $result = imap_fetch_overview($imap,"4200:{$MC->Nmsgs}",0); foreach ($result as $overview) { $nr = "{$overview->msgno}"; $seen = "{$overview->seen}"; if($seen == "0") { $text = imap_fetchbody($imap,$nr,1); $pos = strpos($text, "http");$http = substr($text, $pos);$end = strpos($http, '=');if ($end>0); else $end = strpos($http, " "); if ($end>0) { $link = substr($http, 0, $end);} else { $link = substr($http, 0); } $ok='1'; } } } ?> > [/php][/php]

So it seems $link is not relayed to the script…

So I guess you guys can’t help me with this problem after all ??

Who said that?

I have said before that I would use an AJax poll to test if a new message came in. If it does, you would return the javascript that opens the new message in the new tab AND would activate the sound.

Headfallingoff…

Well, you keep changing the code. Of course it won’t work that way!

First, the ’ echo $ok; " part was to just find out if your email code was passing the correct value of ’ 1 " inside
the variable. It is not needed in the tag.

Next, you switched to setting it to " 5 " for testing and of course when you compare it to " 1 " it will fail.

Your body tag needs to have this in it. If your email checking code is working and passes on the $ok with
a " 1 " in it, this body tag should work for you!
[php]
<body<?php if ($ok=="1") echo " ONLOAD='open2pages();'";?>>
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service