简体   繁体   English

如何使用phpmailer通过位置选择将邮件发送到多个邮件地址?

[英]How to send mail to multiple mail addresses by location selection with phpmailer?

I want the e-mail address to be changed according to the location selection in the registration form.我希望根据注册表中的位置选择更改电子邮件地址。

Example: When Bursa is selected, I want to send an e-mail to bursa@xx.com. Example: When Bursa is selected, I want to send an e-mail to bursa@xx.com. When the city of Antalya is selected, I want an e-mail to antalya@xx.com.选择安塔利亚市后,我想要一封电子邮件至 antalya@xx.com。

HTML: 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: 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";
}

Validate the option, then assign it as the destination:验证选项,然后将其指定为目标:

if (in_array($_POST['Location'], ['istanbul1', 'istanbul2', 'ankara', 'antalya', 'bursa', 'summer'], true)) {
    $mail->addAddress($_POST['Location'] . '@xx.com');
} else {
    die('Nope');
}

I'd also guess you're using an old version of PHPMailer, so upgrade .我也猜你使用的是旧版本的 PHPMailer,所以升级.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM