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 hello@bobmail.info... for some reason it doesn't work with blocking it - can any one see why ?

Link to comment
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!';
}

Link to comment
Share on other sites

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('HELLO@BOBEMAIL.info');//Convert string to lowercase


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

Link to comment
Share on other sites

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

 

$emailArray = array("hello@gmail.com","hello@hotmail.com","hello@bobmail.info");
$newArray = array_filter($emailArray, "removeBobmail");

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

Link to comment
Share on other sites

So what does the new array become ? Just:

 

<?php
$emailArray = array("hello@gmail.com","hello@hotmail.com") ?
?>

 

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 ?

Link to comment
Share on other sites

So what does the new array become ? Just:

 

<?php
$emailArray = array("hello@gmail.com","hello@hotmail.com") ?
?>

 

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] = "your@email.com";
  }
}

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

foreach($emailArray as $i => $e) {
  if(preg_match("/@bobmail\.info/i",$e)) {
    $emailArray[$i] = "your@email.com"; // Set to your admin email.
  }
}
mail($emailArray, $subject, $message, $headers);

This is all you had to do with the code from this thread.

Link to comment
Share on other sites

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

 

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.