EchoFool Posted March 14, 2010 Share Posted March 14, 2010 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 ? Quote Link to comment Share on other sites More sharing options...
slurpee Posted March 14, 2010 Share Posted March 14, 2010 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!'; } Quote Link to comment Share on other sites More sharing options...
GalaxyTramp Posted March 14, 2010 Share Posted March 14, 2010 You might want to convert the string to lower case or this will not work if user enters email address in upper case $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!'; } Quote Link to comment Share on other sites More sharing options...
slurpee Posted March 14, 2010 Share Posted March 14, 2010 You might want to convert the string to lower case or this will not work if user enters email address in upper case That's what the 'i' is for after the delimiter in the preg match. Quote Link to comment Share on other sites More sharing options...
EchoFool Posted March 14, 2010 Author Share Posted March 14, 2010 Ok i worked out the issue - the email is in any array - So say the array hasa list of hello@gmail.com hello@hotmail.com hello@bobmail.info 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" ) Quote Link to comment Share on other sites More sharing options...
slurpee Posted March 14, 2010 Share Posted March 14, 2010 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); } Quote Link to comment Share on other sites More sharing options...
EchoFool Posted March 14, 2010 Author Share Posted March 14, 2010 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 ? Quote Link to comment Share on other sites More sharing options...
slurpee Posted March 14, 2010 Share Posted March 14, 2010 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"; } } Quote Link to comment Share on other sites More sharing options...
EchoFool Posted March 14, 2010 Author Share Posted March 14, 2010 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. Quote Link to comment Share on other sites More sharing options...
slurpee Posted March 15, 2010 Share Posted March 15, 2010 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? Quote Link to comment Share on other sites More sharing options...
Andy-H Posted March 15, 2010 Share Posted March 15, 2010 Why not just use stristr. Quote Link to comment Share on other sites More sharing options...
EchoFool Posted March 15, 2010 Author Share Posted March 15, 2010 Now you've lost =/ Quote Link to comment Share on other sites More sharing options...
slurpee Posted March 15, 2010 Share Posted March 15, 2010 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? Quote Link to comment Share on other sites More sharing options...
EchoFool Posted March 15, 2010 Author Share Posted March 15, 2010 Where was i being vague =/ Basically i have an array of emails and any email which is a "@bobmail.info" i am trying to replace it with a default email (my email) so the email will go to me rather than the bobmail email Quote Link to comment Share on other sites More sharing options...
mattal999 Posted March 15, 2010 Share Posted March 15, 2010 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. Quote Link to comment Share on other sites More sharing options...
EchoFool Posted March 15, 2010 Author Share Posted March 15, 2010 Oh so thats what you meant - i thought i had to execture mail function in every loop ! D'oh ! Thanks guys ! Quote Link to comment Share on other sites More sharing options...
Andy-H Posted March 15, 2010 Share Posted March 15, 2010 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); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.