简体   繁体   English

两个联系表格,发送到两个不同的电子邮件地址

[英]Two contact forms, send to two different email addresses

I got two contact forms on my website. 我的网站上有两个联系表格。 On in the contact section, and one in the careers section. 在“联系”部分中为,在“职业”部分中为。 I want to receive both forms in different email adresses. 我想以不同的电子邮件地址接收这两种形式。

<?php
include_once('class.phpmailer.php');

$mail = new PHPMailer;
$mail->setFrom('adres1','test');

$mail->Subject = 'Contactverzoek via careerspagina.';

$html  = "Er is een contactverzoek gedaan via de careerspagina.<br>";
$html .= "<br>";
$html .= "<b>Naam:</b> " . $_POST['name']."<br>";
if(isset($_POST['lastname'])) {

  $html .= '<b>Achternaam: </b> ' . $_POST['lastname']."<br>";
}
$html .= "<b>E-mail:</b> " . $_POST['email']."<br>";
if(isset($_POST['telefoon'])) {

  $html .= '<b>Telefoon: </b> ' . $_POST['telefoon']."<br>";
}

if(isset($_POST['onderwerp'])) { //FIX NOG!!!
  $html .= '<b>Onderwerp: </b> ' . $_POST['onderwerp']."<br>";
}
if(isset($_POST['Werkervaring'])) {
  $html .= '<b>Werkervaring: </b> ' . $_POST['Werkervaring']."<br>";
}
if(isset($_POST['Functie'])) {
  $html .= '<b>Functie: </b> ' . $_POST['Functie']."<br>";
}
if(isset($_POST['Opleidingsniveaus'])) {
  $html .= '<b>Opleidingsniveaus: </b> ' . $_POST['Opleidingsniveaus']."<br>";
}
if(isset($_POST['comment'])) {
  $html .= '<b>Bericht: </b> ' . $_POST['comment']."<br>";
}
$html .= "<br>";

if (isset($_FILES['resume']) &&
    $_FILES['resume']['error'] == UPLOAD_ERR_OK) {
    $mail->AddAttachment($_FILES['resume']['tmp_name'],
                         $_FILES['resume']['name']);
}

if (isset($_FILES['letter']) &&
    $_FILES['letter']['error'] == UPLOAD_ERR_OK) {
    $mail->AddAttachment($_FILES['letter']['tmp_name'],
                         $_FILES['letter']['name']);
}

$mail->msgHTML($html);
$mail->addAddress('adres1', 'Info ');
$mail->addBCC('adres1', 'Test ');

if(!$mail->send())
{
    echo "0";
}
else
{
    echo "1";
}

This is my code, and everything seems to work. 这是我的代码,一切似乎正常。

So once again. 所以再说一次。 I want to keep sending this contact form to email A. But There needs to be made and else statement which sends the other contact form to email B. 我想继续将此联系表发送到电子邮件A。但是需要做,否则将其他联系表发送到电子邮件B的声明。

i'm very new to PHP. 我是PHP的新手。 Excuse me if i'm not clear. 打扰一下,不好意思。

One simple solution is to send a form parameter indicating which email address should be used. 一种简单的解决方案是发送一个表单参数,指示应使用哪个电子邮件地址。 Then you check the POST variable for that parameter in an if statement and set the correct email address to be used. 然后,在if语句中检查该参数的POST变量,并设置要使用的正确电子邮件地址。

$to = "forma@example.com";
if($_POST['form'] === "formB") {
    $to = "formb@example.com";
}
$mail->addAddress($to, 'Recipient name');

Add hidden inputs in your forms named "form" and set the value to either "formA" or "formB": 在名为“ form”的表单中添加隐藏的输入,并将其值设置为“ formA”或“ formB”:

<input type="hidden" name="form" value="formA">

Do not set the receiving email address in the form and use that since it can easily be abused to send spam from your server. 请勿在表单中设置接收电子邮件地址,并使用该地址,因为它很容易被滥用来从服务器发送垃圾邮件。

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

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