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 [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 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!'; } Link to comment https://forums.phpfreaks.com/topic/195213-blocking-a-email-type/#findComment-1026003 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('[email protected]');//Convert string to lowercase if(preg_match("/@bobmail\.info/i",$bcc_address)) { $bcc_address = ','; $subject = 'Bobmail email was blocked! Voucher unclaimed!'; } Link to comment https://forums.phpfreaks.com/topic/195213-blocking-a-email-type/#findComment-1026014 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. Link to comment https://forums.phpfreaks.com/topic/195213-blocking-a-email-type/#findComment-1026020 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 [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" ) Link to comment https://forums.phpfreaks.com/topic/195213-blocking-a-email-type/#findComment-1026062 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("[email protected]","[email protected]","[email protected]"); $newArray = array_filter($emailArray, "removeBobmail"); function removeBobmail($e) { return !preg_match("/@bobmail\.info/i",$e); } Link to comment https://forums.phpfreaks.com/topic/195213-blocking-a-email-type/#findComment-1026066 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("[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 ? Link to comment https://forums.phpfreaks.com/topic/195213-blocking-a-email-type/#findComment-1026067 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("[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]"; } } Link to comment https://forums.phpfreaks.com/topic/195213-blocking-a-email-type/#findComment-1026069 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. Link to comment https://forums.phpfreaks.com/topic/195213-blocking-a-email-type/#findComment-1026070 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? Link to comment https://forums.phpfreaks.com/topic/195213-blocking-a-email-type/#findComment-1026112 Share on other sites More sharing options...
Andy-H Posted March 15, 2010 Share Posted March 15, 2010 Why not just use stristr. Link to comment https://forums.phpfreaks.com/topic/195213-blocking-a-email-type/#findComment-1026132 Share on other sites More sharing options...
EchoFool Posted March 15, 2010 Author Share Posted March 15, 2010 Now you've lost =/ Link to comment https://forums.phpfreaks.com/topic/195213-blocking-a-email-type/#findComment-1026152 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? Link to comment https://forums.phpfreaks.com/topic/195213-blocking-a-email-type/#findComment-1026204 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 Link to comment https://forums.phpfreaks.com/topic/195213-blocking-a-email-type/#findComment-1026526 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] = "[email protected]"; // 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 https://forums.phpfreaks.com/topic/195213-blocking-a-email-type/#findComment-1026533 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 ! Link to comment https://forums.phpfreaks.com/topic/195213-blocking-a-email-type/#findComment-1026564 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] = "[email protected]"; // Set to your admin email. $subject = 'New Subject'; $message = 'New message'."\r\n"; } mail($emailArray, $subject, $message, $headers); } Link to comment https://forums.phpfreaks.com/topic/195213-blocking-a-email-type/#findComment-1026655 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.