PHP Extract email address from a string [closed]

Use a double explode to find the email.

First explode on the "smtp.mailfrom=" and use the item after ([1]), then on ";" and use the first item in the array as the $email.

$str = "mx.google.com;       dkim=pass [email protected] header.s=selector1 header.b=OvtBcHsM;       spf=pass (google.com: domain of [email protected] designates 12.12.12.12 as permitted sender) [email protected];       dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com";

$mail = explode(";",explode("smtp.mailfrom=", $str)[1])[0];

echo $mail;
//[email protected]

https://3v4l.org/KGCVc

Leave a Comment