0
我在我的頁面上有申請表格。除查詢字符串外,所有內容都正常工作。我想要一個帶有變量的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 = '[email protected]';
$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。
謝謝!
我粘貼了我之前使用過的相同的代碼,並且破壞了我的頁面。說:一個PHP錯誤遇到 嚴重性:注意 消息:未定義指數:MERCHANTID 文件名:庫/的functions.php(688):EVAL()'d代碼 行號:153 線153是帶有隱藏php的行得到 – 2014-09-10 18:16:14
如果你用url中的那個獲取參數加載頁面,它也會中斷嗎?無論如何,應該有一個isset()檢查。見編輯的答案。要驗證您是否將變量獲取到表單中,請在源代碼中查看它。 – MSTannu 2014-09-10 18:21:24
我收到一個意外的錯誤「isset」,我的頁面被完全破壞。 – 2014-09-10 18:33:32