Reputation: 2033
this might be easy but I don´t see the way. I have a shopping cart at my side where user can buy things. for this the buyer can imput his email-adress into an input-form. the order is sent with php mail()
to the shopowner and the buyer.
I´m looking for a way to limit mail to sent only two email, this for preventing spam. I see the risk that spammers could input a semicolon string like this:
email@examplecom;[email protected];[email protected]
Upvotes: 0
Views: 240
Reputation: 14233
Y can't you validate using .
$validemail = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
if ($validemail) {
$headers .= "Reply-to: $validemail\r\n";
}else
{
//redirect.
}
considering your actual question .
<?php
$emails = explode(';',$emailList);
if(count ($emails)<3)
{
if(filter_var_array($emails, FILTER_VALIDATE_EMAIL))
{
mail();
}
else
{
//die
}
}
?>
Upvotes: 5
Reputation: 39522
This should work to only pick maximum two emails (the first two):
$emailString = "email@examplecom;[email protected];[email protected]";
$emails = explode(";", $emailString);
$emails = array_slice($emails, 0, 2);
$emailString = implode(";", $emails);
var_dump($emailString);
Outputs:
string(31) "email@examplecom;[email protected]"
Upvotes: 0
Reputation: 33502
You could check the number of email in the string like this:
if(count(explode(';',$emailList))<3)
{
// send email
}
else
{
// Oh no, jumbo!
}
This code will explode your email string based on the ;
characters into an array while at the same time use a count function on the array and execute one of two scenarios based on the number.
Upvotes: 1