0

我有一个表格,它从下拉菜单中获取我所在的美国,并根据州值打开一个 pdf。我想使用 PHP 根据该值发送不同的电子邮件。我想让他们选择所有 50 多个州,但由于我只需要关心 50 个州中的三个,我可以对电子邮件进行硬编码,即。myAAemail@mydomain.com、myBBemail@mydomain.com 和 myCC@mydomain.com。然后,我想将州名称或值放在电子邮件上,但这不是优先事项。这是我的 if else 语句如何添加电子邮件?我确定我不必提及我是 PHP 新手。

}
if ($_POST['recipient'] == 'AA') {
    header("Location: aa.pdf");
} else if ($_POST['recipient'] == 'BB') {
    header("Location: bb.pdf");          
}else if ($_POST['recipient'] == 'CC') {
    header("Location: cc.pdf");          
}else {
    echo "Error processing form"; 
}

?>
4

1 回答 1

0

您可以使用电子邮件定义关联数组:

$emails = array(
    'AA' => 'email1@mydomain.com',
    'BB' => 'email2@mydomain.com',
    'CC' => 'email3@mydomain.com',
    'DD' => 'email4@mydomain.com',
    'EE' => 'email5@mydomain.com',
    // . . .
);

并将其用作:$mail_address = $emails[$_POST['recipient']];.

}
if ($_POST['recipient'] == 'AA') {
    header("Location: aa.pdf");
} else if ($_POST['recipient'] == 'BB') {
    header("Location: bb.pdf");          
}else if ($_POST['recipient'] == 'CC') {
    header("Location: cc.pdf");          
}else {
    //Mark1
    if ( isset($_POST['recipient']) ) {
        echo "Error processing form"; 
    }
}

if ( isset($emails[$_POST['recipient']]) ) {
    $address = $emails[$_POST['recipient']];
    $subject = 'The mail about ' . $_POST['recipient'];
    $message = "Hello, I'm writing the mail about " . $_POST['recipient'];

    mail($address, $subject, $message);
} 

?>
于 2013-10-06T13:39:05.763 回答