I realized that the filter_var()
function does not email with my php 5.1.6
which gives me the following error: Call to undefined function filter_var()
my code is:
while ( $row = mysql_fetch_assoc( $result ) ) {
if( filter_var($row['EMAIL1_CLI'], FILTER_VALIDATE_EMAIL) ){
//$return .= '<label>Correo enviado a ' . $row['EMAIL1_CLI'] . '</label></br>';
$html .= enviar_mail( $row, $row['EMAIL1_CLI'] );
}elseif( filter_var($row['EMAIL2_CLI'], FILTER_VALIDATE_EMAIL) ){
//$return .= '<label>Correo enviado a ' . $row['EMAIL2_CLI'] . '</label></br>';
$html .= enviar_mail( $row, $row['EMAIL2_CLI'] );
}else{
$html .= '<h4 style="text-align:center; color: red;">Ninguno de los correos es valido</h4>';
}
the code needs to validate the (valid) emails that are in the field EMAIL1_CLI
and EMAIL2_CLI
of the BD, and then send them through the function.
someone can help me adapt it so that it runs in php 5.1.6
try with preg_match_all
:
$regexp = '/[a-z0-9_\-\+\.]+@[a-z0-9\-]+\.([a-z]{2,4})(?:\.[a-z]{2})?/i';
while ( $row = mysqli_fetch_array( $result ) ) {
$mail1 = $row['EMAIL1_CLI'];
$mail2 = $row['EMAIL2_CLI'];
$datos = array();
$datos['EMAIL1_CLI'] = $mail1;
$datos['EMAIL2_CLI'] = $mail2;
preg_match_all($regexp, $mail1, $matches);
preg_match_all($regexp, $mail2, $matches2);
if( filter_var($row['EMAIL1_CLI'], FILTER_VALIDATE_EMAIL) ){
//$return .= '<label>Correo enviado a ' . $row['EMAIL1_CLI'] . '</label></br>'; // mostrar correos enviados
$html .= enviar_mail( $datos, trim( $matches[0][0]) );
}elseif( filter_var($row['EMAIL2_CLI'], FILTER_VALIDATE_EMAIL) ){
//$return .= '<label>Correo enviado a ' . $row['EMAIL2_CLI'] . '</label></br>'; // mostrar correos enviados
$html .= enviar_mail( $datos, trim( $matches2[0][0]) );
}else{
$html .= '<h4 style="text-align:center; color: red;">Ninguno de los correos es valido</h4>';
}
//$return .= '<hr>'; //espacios entre codigos enviados a mostrar
}