我希望根据注册表格中的位置选择更改电子邮件地址。
示例:选择Bursa后,我想发送电子邮件至bursa@xx.com。选择安塔利亚市后,我希望发送电子邮件至antalya@xx.com。
HTML:
<label class="sr-only" for="Location">Preferred Location: *: *</label>
Preferred Location: * *<select required class="form-control" id="Location" name="Location">
<option value="istanbul1" >Ümraniye</option>
<option value="istanbul2">Beylikdüzü</option>
<option value="ankara">Ankara</option>
<option value="antalya">Antalya</option>
<option value="bursa">Bursa</option>
<option value="summer">Summer Camp</option>
</select>
PHP:
$mail = new PHPMailer(); // create a new object
$subject = "[XX] Registration Form";
$question = nl2br(stripcslashes($_POST['question']));
$question = trim($question);
$email_message = "<b>Name:</b> ".stripcslashes($_POST['fname'])."<br><br>";
$email_message .= "<b>Surname:</b> ".stripcslashes($_POST['lname'])."<br><br>";
$email_message .= "<b>Birthday:</b> ".stripcslashes($_POST['dob'])."<br><br>";
$email_message .= "<b>Gender:</b> ".stripcslashes($_POST['gender'])."<br><br>";
$email_message .= "<b>Phone:</b> ".stripcslashes($_POST['phone'])."<br><br>";
$email_message .= "<b>Email:</b> ".stripcslashes($_POST['email'])."<br><br>";
$email_message .= "<b>Address:</b> ".stripcslashes($_POST['adres'])."<br><br>";
$email_message .= "<b>Location:</b> ".stripcslashes($_POST['Location'])."<br><br>";
$body = $email_message;
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->Host = "smtp.yandex.com.tr";
$mail->SMTPSecure = 'ssl';
$mail->Port = 465; // or 465
$mail->IsHTML(true);
$mail->CharSet ="utf-8";
$mail->SetFrom("info@xx.com", "XX REGISTRATION FORM"); // Mail adresi
$mail->Username = "info@xx.com"; // Mail adresi
$mail->Password = "xxx"; // Parola
$mail->Subject = $subject;
$mail->body = $body;
$mail->MsgHTML($body);
$mail->AddAddress("info@xx.com");
$mail->AddAddress("antalya@xx.com");
$mail->addReplyTo(stripcslashes($_POST['emailer']), "");
if(!$mail->Send()){
echo "Mesaj hatası: ".$mail->ErrorInfo;} else {
echo "Mesaj Gönderildi";
}
答案 0 :(得分:0)
验证选项,然后将其分配为目的地:
if (in_array($_POST['Location'], ['istanbul1', 'istanbul2', 'ankara', 'antalya', 'bursa', 'summer'], true)) {
$mail->addAddress($_POST['Location'] . '@xx.com');
} else {
die('Nope');
}
我也可能猜到您使用的是旧版本的PHPMailer,所以upgrade。