Reputation: 15
i have a string like:
$str = '[email protected][[email protected] has mail me][email protected][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 = '[email protected]';
$msg = '[email protected] has mail me';
$to = '[email protected]';
$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 = '[email protected]';
$go = mail($to, $subject, $message, $headers);
if($go)
{
echo 'good result';
}
}
great thanks for your impact in my soluction
Upvotes: 0
Views: 38
Reputation: 1132
You can use a regular expression, check here https://regex101.com/r/7khpKv/1
$regExpresion = '/(.*?)\[(.*?)\]/';
$str = '[email protected][[email protected] has mail me][email protected][i want to...][email protected][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: [email protected]';
$go = mail($to, $subject, $message, $headers);
if ($go)
{
echo 'good result';
}
}
Upvotes: 0
Reputation: 26844
You can explode
it:
$str = '[email protected][[email protected] has mail me][email protected][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: [email protected]
Msg: [email protected] has mail me
Email: [email protected]
Msg: i want to...
Upvotes: 1