有很多關於此的其他文章。我經歷了幾次嘗試數組並在$ to字段等中輸入電子郵件,但是如果指定了一封電子郵件,我的表單只會繼續發送。我究竟做錯了什麼?我也是PHP noob。獲取此PHP表單發送給多個收件人?
<?php
// EVALUATION FORM
$your_email = '[email protected], [email protected]';
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;
}
}
?>
您能否提供您在窗體中發送的值? – Novak
爲什麼不添加「cc:」到標題,就像這個答案http://stackoverflow.com/questions/3582126/php-mail-cc-field – vogomatix
Google是你的朋友。一個簡單的'發送電子郵件到多個地址在PHP'搜索將帶來很多有用的信息。 – MikeF