Dave Dave - 1 month ago 5x
PHP Question

Explode a result and Assign them to a Variables

I have an input field, which consist of different email addressess. I want to be able to loop through this input on submit, and assign each to a variable so, i could use them for processing. See my code and tell me where I am missing it:

<input type="email" name="m" placeholder-"Enter Email address separated by (;)"/>
<input type="submit" name="sbt" value="Submit"/>

$myMail = $_POST['m'];
$res = explode(";",$myMail);
foreach($res as $ml=>$value){
echo '$us'.$ml."=".$value.";<br/>";

I want the result to be :$us0 = ade.yemi@yahoo.com;
$us1 = ade.yemi@yahoo.com;
$us2 = nifemi.ola@gmail.com;
but it is show undefined variables for $us0;$us1;$us2.

Please help or is there is a better way, as i want to make use of these variable for CC aspect in phpmailer.


This row: $res = explode(";",$myMail); will give you an array with all the email addresses, like:

   0 => 'some-address@example.com', 
   1 => 'another@example.com', 

Why not just use that array?

Fetch the e-mail addresses like this, where you need them:

$phpMailer->addCC($res[1]); // Or what the syntax for PHPMailer is...