Jump to content

Blocking a email type


EchoFool

Recommended Posts

Hey,

 

I have a script which allows people to purchase - but i wish to block an email "bobmail.info" so i put this:

 

  <?php      if (eregi('@bobmail.info', $bcc_address)) {
            $bcc_address = ',';
            $subject = 'Bobmail email was blocked! Voucher unclaimed!';
            }
?>

 

So say $bbc_address was [email protected]... for some reason it doesn't work with blocking it - can any one see why ?

Link to comment
https://forums.phpfreaks.com/topic/195213-blocking-a-email-type/
Share on other sites

ereg and eregi are depricated in php 5.3 and will be removed in 6.0, so I highly suggest against using those functions.  Instead, just use preg_match():

 

if(preg_match("/@bobmail\.info/i",$bcc_address)) {
  $bcc_address = ',';
  $subject = 'Bobmail email was blocked! Voucher unclaimed!';
}

You might want to convert the string to lower case or this will not work if user enters email address in upper case  :D

 

$bcc_address = strtolower('[email protected]');//Convert string to lowercase


if(preg_match("/@bobmail\.info/i",$bcc_address)) 
        {
            $bcc_address = ',';
            $subject = 'Bobmail email was blocked! Voucher unclaimed!';
        }

Ok i worked out the issue - the email is in any array -

 

So say the array hasa list of

 

[email protected]

[email protected]

[email protected]

 

how can i replace just the bobmail info with some other email ? (note the email could be in any position of the array and obviously won't always be "hello" )

This will totally clean the array from all emails that match "@bobmail.info"

 

$emailArray = array("[email protected]","[email protected]","[email protected]");
$newArray = array_filter($emailArray, "removeBobmail");

function removeBobmail($e) {
  return !preg_match("/@bobmail\.info/i",$e);
}

So what does the new array become ? Just:

 

<?php
$emailArray = array("[email protected]","[email protected]") ?
?>

 

Because what i was thinking was "replace" bobmail with my admin email so i get notified - but str_replace doesn't work on arrays does it ?

 

Why can't you just go through the array with a for loop?

 

foreach($emailArray as $i => $e) {
  if(preg_match("/@bobmail\.info/i",$e)) {
    $emailArray[$i] = "[email protected]";
  }
}

Because the mail function i just put the array in the list like

<?php
mail($EmailArray, $subject, $message, $headers);
?>

So to go through the array means executing mail function many times instead of just once. :)

 

But what about executing the for loop before you call the mail function?

Now you've lost =/

 

How about you try and explain your problem better so you can get a better answer? There are about 4 solutions that will all probably work with your code if you just mess around with it a little.  We can't give you accurate help since you're being so vague with your questions.

 

So, either explain exactly what you need a little better than you already have, or how about posting a bit more code so we can try it out for ourselves?

 

foreach($emailArray as $i => $e) {
  $subject  = 'Subject';
  $message  = 'blah blah'."\r\n";
  $headers  = 'Your headers';
  if( stristr($e, '@bobmail.info') !== false ) {
    $emailArray[$i] = "[email protected]"; // Set to your admin email.
    $subject  = 'New Subject';
    $message  = 'New message'."\r\n";
  }
mail($emailArray, $subject, $message, $headers);
}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.