There are a lot of other posts about this. I have gone through several and tried arrays and inputting emails in the $to field and the like but my form keeps only sending if I specify one email. What am I doing wrong? I'm a PHP noob too.
<?php
// EVALUATION FORM
$your_email = 'email1@address.com, email2@address.com';
session_start();
$errors = '';
$name = '';
$visitor_email = '';
$phone = '';
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$phone = $_POST['phone'];
///------------Do Validations-------------
if (empty($name) || empty($visitor_email)) {
$errors .= "\n Form was not submitted. Please fill out all the fields. ";
}
if (IsInjected($visitor_email)) {
$errors .= "\n Bad email value!";
}
if (empty($_SESSION['6_letters_code']) || strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0) {
//Note: the captcha code is compared case insensitively.
//if you want case sensitive match, update the check above to
// strcmp()
$errors .= "\n The captcha code does not match!";
}
if (empty($errors)) {
//send the email
$to = $your_email;
$subject = "Free Injury Evaluation form submission from Northwest Injury Centers";
$from = $your_email;
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
$body = "$name submitted the Free Injury Evaluation form:\n\n" . "Name: $name\n" . "Email: $visitor_email \n" . "Phone: $phone \n" . "IP: $ip\n";
$headers = "From: $from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to, $subject, $body, $headers);
header('Location: thankyou.php');
}
}
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array(
'(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if (preg_match($inject, $str)) {
return true;
} else {
return false;
}
}
?>