PHP根据combobox中选择的值发送电子邮件

时间:2013-02-07 05:40:27

标签: php email button combobox

我想发送两封不同的电子邮件,通知申请人申请奖学金。如果用户从组合框中选择“批准”,则系统将自动向申请人的电子邮件地址发送电子邮件通知,否则将发送撤销通知。这是我到目前为止所尝试的内容:

<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $id; ?>"/>
<strong>Applicant ID:</strong> <?php echo $id; ?><br />
<strong>Applicant name: </strong> 
<input type="text" name="username" readonly value="<?php echo $lastname. "," . $firstname. " " .substr($middlename, 0,1); ?>"/><br/>
<strong>Username: </strong><input type="text" readonly name="username" value="<?php echo $username; ?>" /> <br />
<strong>Password: </strong><input type="text" readonly name="password" value="<?php echo $password; ?>" /> <br />

<strong>Manage Application: </strong><select name="status">
<?php
    $selection = array(
    0 => "Pending",
    1 => "Approve",
    2 => "Revoke" );

    foreach($selection as $key => $value)
    {
        echo '<option value="' . $key . '"';
        if ($status == $key)
        echo ' selected="selected"';
        echo '>' . $value . '</option>';
        echo ' <br />';
    }
?>
</select>
<br />

<button type="submit" name="submit" value="Submit"><img src="../../images/login.png"   />Update</button>


<?php 

if(isset($_POST['submit']))
{
if($selection == 1){

$to = '.$email.';
//define the subject of the email
$subject = 'Test email'; 
//define the message to be sent. Each line should be separated with \n
$message = "Hello World!\n\nThis is my first mail."; 
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
//send the email
if (mail($to, $subject, $message, $headers)) {
echo("<p>Congrats!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
}
else if($selection == 2)
{
$to = $email;
//define the subject of the email
$subject = 'Test email'; 
//define the message to be sent. Each line should be separated with \n
$message = "Hello World!\n\nThis is my first mail."; 
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
//send the email
if (mail($to, $subject, $message, $headers)) {
echo("<p>Sorry your application is revoked!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
}


} // end of if button pressed

?>

 <a href="../index.php"><button type="button"><img src="../../images/back.png"/>Back</button></a>
</div>
</form> 

但是当我检查电子邮件时它没有发送。这是对的吗?

  $to = $email;

我从一行['EmailAddress']获得了$ email;

请帮我弄清楚我错过了什么。感谢。

1 个答案:

答案 0 :(得分:0)

我认为你的价值已经上涨了。所以得到这样的$to=$_POST["your email address field name"]。希望它能正常工作。试试吧。

尝试下面的ode

<?php
$selection = array(
0 => "Pending",
1 => "Approve",
2 => "Revoke" );

$选项= “”;

foreach($selection as $key => $value)
{
    if ($status == $key)
        $sel='selected="selected"';

    $option.='<option value="'. $key.'" '.$sel.'>'. $value . '</option>';


    echo $option.' <br />';
}

&GT;

相关问题