从表单发送电子邮件

时间:2017-06-05 14:08:46

标签: php email send

我正在创建一个评估,将结果发送给老师和学生。我无法将结果发送给学生,只有老师。以下是我的内容:

的index.php

<form id="form1" name="form1" method="post" action="results.php" onsubmit="return validateForm() ;">

<label>First Name
<input type="text" name="fname" id="fname" tabindex="1" />
                  </label>
<label>Last Name
<input type="text" name="lname" id="lname" tabindex="2" />
</label>

<label>Title
<input type="text" name="title" id="title" tabindex="3" />
</label>

<br />
<br />
<hr />

<?php

$quiz = new Quiz( $questions );
echo $quiz->renderQuiz();

?>      

<br/>
<label>Enter the email addresses you would like to receive your results, separated by semicolons.</label><br/>
<input type="text" name="email_to" tabindex="4" size="80" /> 
<input name="Submit" type="submit" value="Submit" />    
</form>

results.php

$force_email = array( "test@test.com", test1@test.com);

function create_email_string( $force_email, $user_input )
{
    if (!empty( $user_input )) 
    {
            $email_string = $user_input . "; " . implode("; " , $force_email);
    }

    else 
    {
            $email_string = implode("; " , $force_email);
    }

    return $email_string;
}
$ip = $_SERVER['REMOTE_ADDR']; // employee's Ip address
$time = date("d/m/y : H:i:s", time()); // current timestamp
$email_string = create_email_string( $force_email, $_POST['email_to'] );
$questions_correct = array();
$results_data_page = $_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"];
$file_start = (strrpos($results_data_page, "/")+1);
$results_data_page = substr_replace($results_data_page, "results_data_page.php?test_name=" . rawurlencode($test_name), $file_start);
$variables = array();
$variables['fname'] = $_POST['fname'];
$variables['lname'] = $_POST['lname'];
$variables['test_name'] = $test_name;
$variables['score'] = $score;
$variables['table'] = create_results_table( $questions, $questions_correct     );
$variables['results_data_page'] = $results_data_page;

$subject = $variables['fname'] . " " . $variables['lname'] . " results - " . $test_name;

$headers = "From: test@test.com\n";
$headers .= "Reply-To: test@test.com \n";
$headers .= "MIME-Version: 1.0 \n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1 \n";
$headers .= "Content-Transfer-Encoding: base64";

$message = getMessage( $variables );
$message = rtrim(chunk_split(base64_encode($message)));

foreach ($force_email as $to) {
    mail($to, $subject, $message, $headers);
}

0 个答案:

没有答案