Good evening. It is the first time that I occupy this platform to make a query, I hope you can help me.
I have already created a form for a telephone company. It is assumed that the way it works is that depending on the selected city, the information is sent to the emails assigned to each city. I already have that functional.
The question is that my client asks me to select the city of Veracruz, the information is sent to an email chosen at random from an array containing 3 different emails.
<?php
$to = $_POST['to'];
$correosver = array("[email protected]", "[email protected]", "cotizaciones@$$$.com.mx");
$randIndex = array_rand($correosver, 1);
$subject = $_POST['subject'];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: ".$_POST['nombre']."<".$_POST['email'].">\r\n";
$headers .= "Reply-To: ".$_POST["email"]."\r\n";
$ciudad = $_POST['ciudad'];
$message = "<table>
<tr><td>Quiero: </td><td>".$_POST['quiero']."</td></tr>
<tr><td>Nombre: </td><td>".$_POST['nombre']."</td></tr>
<tr><td>Ciudad: </td><td>".$_POST['ciudad']."</td></tr>
<tr><td>Email: </td><td>".$_POST['email']."</td></tr>
<tr><td>Teléfono: </td><td>".$_POST['tel']."</td></tr>
<tr><td>Companía: </td><td>".$_POST['compania']."</td></tr>
<tr><td>Contrato: </td><td>".$_POST['plan']."</td></tr>
<tr><td>Equipo: </td><td>".$_POST['equipo']."</td></tr>
<tr><td>Dudas: </td><td>".$_POST['dudas']."</td></tr>
</table>" ;
if($ciudad == 'veracruz') {
$to = $randIndex;
}
else if($ciudad == 'alvarado') {
$to = 'cotizaciones@###.com.mx';
}
else if($ciudad == 'tuxtepec') {
$to = 'supervisorcuenca@###.com.mx, cotizaciones@###.com.mx';
}
else if($ciudad == 'poza_rica') {
$to = 'supervisorpozarica@###.com.mx, cotizaciones@###.com.mx';
}
else if($ciudad == 'xalapa') {
$to = 'supervisorxalapa@###.com.mx, cotizaciones@###.com.mx';
}
else if($ciudad == 'san_andres') {
$to = 'supervisorcuenca@###.com.mx, cotizaciones@###.com.mx';
}
if(mail($to, $subject, $message, $headers)){
header("Location: /index.html");
exit; // we are sending this text to the ajax request telling it that the mail is sent..
}else{
echo 'failed';// ... or this one to tell it that it wasn't sent
}
?>
I'm occupying an array with the emails:
$correosver = array("[email protected]", "[email protected]", "cotizaciones@$$$.com.mx");
And an array_rand with index to index and shuffle the elements of the array:
$randIndex = array_rand($correosver, 1);
My logic indicates that selecting veracruz the variable $to
is equal to the random content of the variable $randIndex
.
if($ciudad == 'veracruz') {
$to = $randIndex;
}
I do not know if my syntax is correct or that I am doing wrong, but the emails do not reach their recipients and I do not have any type of error. I do not know if they could help me or point me out any other way to address this problem. Greetings.