<?php
error_reporting(-1);

$text = "Sample text for testing:
abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789 +-.,!@#$%^&*();\/|<>'
12345 -98.7 3.141 .6180 9,000 +42
555.123.4567	+1-(800)-555-2468
foo@demo.net	bar.ba@test.co.uk
www.demo.com	http://f...content-available-to-author-only...o.uk/
http://r...content-available-to-author-only...r.com/foo.html?q=bar
mail@mail.ru waka@wak.rc.uk
user0+test+hello_world@100500.com
user%office@company.com
BIGBOSS@BIGCOMPANY.COM
";

function grabEmail($text) { //между названием функции и () не ставится пробел.
	$emailRegexp = '/[\w\.%_\+-]+@[\w\._-]+/i';
	$matches = [];
	$count = preg_match_all($emailRegexp, $text, $matches, PREG_SET_ORDER);
	foreach ($matches as $emails) {
		$mail[] = $emails[0];
		echo "$emails[0]\n";
	}
	return $mail;
}

grabEmail($text);