我的页面上有申请表。除查询字符串外,一切正常。我想带一个带变量的url,并将其传递给联系表单电子邮件。防爆。 http://www.example.net?merchantid=12345
我希望商家ID变量名称和值显示在我收到的电子邮件中,以及其他用户信息。它现在的方式打破了我的页面。发送没有此商家ID的CC电子邮件会很棒。
这是我的标记:
<form id="shortApplication" action="{site_url}application#contact-sent" method="POST" enctype="multipart/form-data" data-type="advanced">
<input type="hidden" value="true" name="emailSent" id="emailSent">
<input type="hidden" name="XID" value="{XID_HASH}" />
<input type="hidden" name="merchantid" value='<?php echo $merchantid; ?>' />
<div class="row">
<div class="form-group">
<div class="col-md-6">
<label>Your First Name *</label>
<input type="text" value="" required data-msg-required="Please enter your first name." maxlength="100" class="form-control" name="first_name" id="first_name">
</div>
<div class="col-md-6">
<label>Your Last Name *</label>
<input type="text" value="" required data-msg-required="Please enter your last name." maxlength="100" class="form-control" name="last_name" id="last_name">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-6">
<label>Your Business Name *</label>
<input type="text" value="" required data-msg-required="Please enter your business name." maxlength="100" class="form-control" name="business_name" id="business_name">
</div>
<div class="col-md-6">
<label>Your Phone Number *</label>
<input type="text" value="" required data-msg-required="Please enter your phone number." maxlength="100" class="form-control" name="phone" id="phone">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-6">
<label>Your email address *</label>
<input type="email" value="" required data-msg-required="Please enter your email address." data-msg-email="Please enter a valid email address." maxlength="100" class="form-control" name="email" id="email">
</div>
<div class="col-md-6">
<label>Confirm Your email address *</label>
<input type="email" value="" required data-msg-required="Emails must match." data-msg-email="Please enter a valid email address." maxlength="100" class="form-control required email" equalTo='#email' name="emailConfirm" id="emailConfirm">
</div>
</div>
</div>
<div class="row">
<div class="checkbox">
<div class="form-group">
<div class="col-md-6">
<label>
<input type="checkbox" id="checked"> I agree to the <a href="{site_url}terms-and-conditions" target="_blank">terms & conditions</a>
</label>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<label>Human Verification *</label>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-4">
<div class="captcha form-control">
<div class="captcha-image">
<?php
$_SESSION['captcha'] = simple_php_captcha(array(
'min_length' => 6,
'max_length' => 6,
'min_font_size' => 22,
'max_font_size' => 22,
'angle_max' => 3
));
$_SESSION['captchaCode'] = $_SESSION['captcha']['code'];
echo '<img src="' . "php/simple-php-captcha/simple-php-captcha.php/" . $_SESSION['captcha']['image_src'] . '" alt="CAPTCHA code">';
?>
</div>
</div>
</div>
<div class="col-md-8">
<input type="text" value="" maxlength="6" data-msg-captcha="Wrong verification code." data-msg-required="Please enter the verification code." placeholder="Type the verification code." class="form-control" name="captcha" id="captcha">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<hr>
</div>
</div>
<div class="row">
<div class="col-md-12">
<input type="submit" id="shortApplicationSubmit" value="Send Message" class="btn btn-primary btn-lg pull-right" data-loading-text="Loading..." disabled="disabled">
</div>
</div>
</form>
这是我的PHP:
<?php
session_start();
include("php/simple-php-captcha/simple-php-captcha.php");
include("php/php-mailer/class.phpmailer.php");
// Step 1 - Enter your email address below.
$to = 'info@novawebdev.com';
$arrResult = array('response'=>'');
if(isset($_POST['emailSent'])) {
$subject = 'RTO Camera Application';
// Step 2 - If you don't want a "captcha" verification, remove that IF.
if (strtolower($_POST["captcha"]) == strtolower($_SESSION['captcha']['code'])) {
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$business_name = $_POST['business_name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$merchantid = $_GET['merchantid'];
// $emailConfirm = $_POST['emailConfirm'];
// Step 3 - Configure the fields list that you want to receive on the email.
$fields = array(
0 => array(
'text' => 'First Name',
'val' => $_POST['first_name']
),
1 => array(
'text' => 'Last Name',
'val' => $_POST['last_name']
),
2 => array(
'text' => 'Business Name',
'val' => $_POST['business_name']
),
3 => array(
'text' => 'Phone Number',
'val' => $_POST['phone']
),
4 => array(
'text' => 'Email',
'val' => $_POST['email']
),
5 => array(
'text' => 'Merchant ID',
'val' => $_POST['merchantid']
)
);
$message = "";
foreach($fields as $field) {
$message .= $field['text'].": " . htmlspecialchars($field['val'], ENT_QUOTES) . "<br>\n";
}
$mail = new PHPMailer;
$mail->IsSMTP();
// Step 4 - If you don't receive the email, try to configure the parameters below:
//$mail->Host = 'mail.yourserver.com'; // Specify main and backup server
//$mail->SMTPAuth = true; // Enable SMTP authentication
//$mail->Username = 'username'; // SMTP username
//$mail->Password = 'secret'; // SMTP password
//$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = $email;
$mail->FromName = $_POST['first_name'].' '.$_POST['last_name'];
$mail->AddAddress($to);
$mail->AddReplyTo($email, $first_name, $last_name);
$mail->AddCC($email);
$mail->IsHTML(true);
$mail->CharSet = 'UTF-8';
$mail->Subject = $subject;
$mail->Body = $message;
if($mail->Send()) {
$arrResult['response'] = 'success';
} else {
$arrResult['response'] = 'error';
}
} else {
$arrResult['response'] = 'captchaError';
}
}
?>
我已经研究了几个小时了,这就是我走了多远。在联系表单的基本复制粘贴之外,我从未使用过PHP。
谢谢!
答案 0 :(得分:1)
你快到了。在你的
<input type="hidden" name="merchantid" value='<?php echo $merchantid; ?>' />
确保使用get参数设置$ merchantid:
<input type="hidden" name="merchantid" value="<?php if ( isset( $_GET['merchantid'] ) ) echo $_GET['merchantid']; ?>" />
然后它将以
的形式提供$merchantid = $_POST['merchantid'];
在你的处理功能中。