i have a string like:
$str = 'xyz@email.com[24ab@gmail.com has mail me]abc@email.Com[i want to...] and others...';
in my achievement i want to be able to use the text inside the box as an email message to email behind the box like:
$to = 'xyz@email.com';
$msg = '24ab@gmail.com has mail me';
$to = 'abc@email.com';
$msg = 'i want to...';
i dont really no how to run on php i just want to do some thing am sorry
foreach($str as $both)
{
$to = $both["to"];
$msg = $both["msg"];
$to = $email;
$subject = 'the subject';
$message = '$msg';
$headers = 'stringemail@gm.Com';
$go = mail($to, $subject, $message, $headers);
if($go)
{
echo 'good result';
}
}
great thanks for your impact in my soluction
You can explode
it:
$str = 'xyz@email.com[24ab@gmail.com has mail me]abc@email.Com[i want to...]';
$str = explode( "]", $str );
foreach ( $str as $value ) {
$temp = explode( "[", $value );
if ( count( $temp ) == 2 ) {
echo "<br /> Email: " . $temp[0]; /* $temp[0] - is the email */
echo "<br /> Msg: " . $temp[1]; /* $temp[1] - is the message */
echo "<br />";
}
}
This will result to:
Email: xyz@email.com
Msg: 24ab@gmail.com has mail me
Email: abc@email.Com
Msg: i want to...
You can use a regular expression, check here https://regex101.com/r/7khpKv/1
$regExpresion = '/(.*?)\[(.*?)\]/';
$str = 'xyz@email.com[24ab@gmail.com has mail me]abc@email.Com[i want to...]434343@wewe.com[other mesage]';
preg_match_all($regExpresion, $str, $aMatches, PREG_SET_ORDER, 0);
foreach ($aMatches as $aMail)
{
$to = $aMail[1];
$message = $aMail[2];
$subject = 'the subject';
$headers = 'From: stringemail@gm.Com';
$go = mail($to, $subject, $message, $headers);
if ($go)
{
echo 'good result';
}
}