使用 If 其他方式发送邮件


send mail using if else

我有一个表单,它从下拉菜单中获取美国 I 州并根据州值打开一个 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"; 
}
?>

您可以定义一个带有电子邮件的关联数组:

$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);
} 
?>