我正在尝试使用PHP中的不同联系表单,但其中一个目前正在工作,另一个不是。 这是我正在使用的代码:
require 'php/class.phpmailer.php';
require 'php/PHPMailerAutoload.php';
require 'php/class.smtp.php';
/*Send message CONTACT FORM*/
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587; // or 587
$mail->IsHTML(true);
$mail->Username = "email@gmail.com";
$mail->Password = "password";
$name = $_POST['txtName'];
$message = $_POST['txtMessage'];
$email = $_POST['txtEmail'];
$emailC = $_POST['txtEmailC'];
$mail->SetFrom("example@gmail.com");
$mail->Name = $name;
$mail->Subject = $email;
$mail->Body = 'Name: ' .$name .' Message: ' .$message . ' Email: ' .$email;
$mail->AddAddress("email@domain.com");
if (isset($_POST['btnSend']))
{
if($email !== $emailC)
{
echo '<script type="text/javascript">alert("Emails are not matching");</script>';
}
else
{
if(!$mail->Send())
{
echo '<script type="text/javascript">alert("Data has been submitted to ' . $mail->ErrorInfo . '");</script>';
header("Refresh:0");
}
else
{
echo '<script type="text/javascript">alert("Your message was sent correctly!");</script>';
header("Refresh:0");
}
}
}
$request = new PHPMailer();
$request->IsSMTP(); // enable SMTP
$request->SMTPAuth = true; // authentication enabled
$request->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for Gmail
$request->Host = 'smtp.gmail.com';
$request->Port = 587;
$request->IsHTML(true);
$request->Username = "email@gmail.com";
$request->Password = "password";
//Set of the variables
$fn = $_POST['txtFirstName'];
$ln = $_POST['txtLastname'];
$pn = $_POST['txtPhoneNumber'];
$em = $_POST['txtEmail'];
$cm = $_POST['txtCompany'];
$tt = $_POST['txtTitle'];
$sd = $_POST['slDemo'];
$request->SetFrom("email@gmail.com");
$request->Name = $fn + " " + $ln;
$request->Subject = "Demo Request: " + $sd;
$request->Body = 'Requester Name: ' .$fn .' Requester Lastname: ' .$ln . ' Requester #Number: ' .$pn . 'Requester Email: ' .$em . 'Requester Company: ' .$cm . 'Requester title: ' .$tt . 'Requester DEMO: ' .$sd;
$request->AddAddress("email@domain.com");
try
{
if (isset($_POST['btnRequest']))
{
if(!$request->Send())
{
echo '<script type="text/javascript">alert("Data has been submitted to ' . $request->ErrorInfo . '");</script>';
//header("Refresh:0");
echo 'Data was submitted';
}
else
{
echo '<script type="text/javascript">alert("Your message was sent correctly!");</script>';
//header("Refresh:0");
echo 'Your message was snet';
}
}
}
catch(Exception $ex)
{
echo '<script type="text/javascript">alert("There was an error: ! ' + $ex- >getMessage() +'");</script>';
echo '<script type="text/javascript">alert("There was an error: !");</script>';
header("Refresh:0");
}
这些是以下两者的HTML代码:
<form method="post" role="form">
<div class="col-md-12">
<h4>Request Demo Form</h4>
<div class="col-md-6">
<div class="clearfix"></div>
<input id="txtFirstName" class="form-control" placeholder="First name" name="rqFirstname" required />
<input style="margin-top: 2%;" id="txtLastname" class="form-control" placeholder="Last name" name="rqLastname" required/>
<input style="margin-top: 2%;" id="txtPhoneNumber" class="form-control" placeholder="Phone number" name="rqPhone" required />
</div>
<div class="col-md-6">
<input id="txtEmail" class="form-control" placeholder="Your email" name="rqPEmail" required />
<input style="margin-top: 2%;" id="txtCompany" class="form-control" placeholder="Company" name="rqCompany" required/>
<input style="margin-top: 2%;" id="txtTitle" class="form-control" placeholder="Your Title" name="rqTitle" required/>
</div>
</div>
<div class="col-md-12">
<h4>Demo</h4>
<div class="col-md-6">
<div class="clearfix"></div>
<select name="demoSelection" id="slDemo" style="margin-top: 2%;" class="form-control">
<option class="text-muted">-- Choose your demo --</option>
<option value="Commisions">Commisions</option>
<option value="CPQ">CPQ</option>
<option value="ImprovedApps">ImprovedApps</option>
<option value="MarketingAutomation">Marketing Automation</option>
<option value="DataCleansing">Data Cleansing</option>
<option value="SalesCoachihg">Sales Coaching & Learning Management</option>
</select>
</div>
<div class="col-md-6">
<div style="margin-top: 2%;" class="footer pull-right">
<input type="submit" class="btn btn-primary btn-sm" value="Request" id="btnRequest" />
</div>
</div>
</div>
</form>
这是第二种形式
<form method="post" role="form">
<div class="well well-sm"><small><span class="glyphicon glyphicon-asterisk"></span> Required Field</small></div>
<div class="form-group">
<div class="input-group">
<input type="text" class="form-control input-sm" name="txtName" id="InputName" placeholder="Enter your Name" required>
<span class="input-group-addon"><span class="glyphicon glyphicon-asterisk"></span></span>
</div>
</div>
<div class="form-group">
<div class="input-group">
<input type="email" class="form-control input-sm" id="InputEmail" name="txtEmail" placeholder="Enter your Email" required>
<span class="input-group-addon"><span class="glyphicon glyphicon-asterisk"></span></span>
</div>
</div>
<div class="form-group">
<div class="input-group">
<input type="email" class="form-control input-sm" id="txt" name="txtEmailC" placeholder="Confirm your Email" required>
<span class="input-group-addon"><span class="glyphicon glyphicon-asterisk"></span></span>
</div>
</div>
<div class="form-group">
<div class="input-group">
<textarea id="InputMessage" class="form-control input-sm" name="txtMessage" placeholder="Your message here..." rows="5" required></textarea>
<span class="input-group-addon"><span class="glyphicon glyphicon-asterisk"></span></span>
</div>
</div>
<button type="button" class="btn btn-default btn-sm" data-dismiss="modal">Close</button>
<button data-toggle="tooltip" data-placement="left" title="Remember to fill correctly every field before sending you message." type="submit" name="btnSend" id="submit" class="btn btn-info btn-sm pull-right"><i class="glyphicon glyphicon-share-alt"></i> Submit</button>
</form>
我要做的是创建一个联系表单并请求联系,两种不同的形式。还有其他更好的方法吗? 请有人能告诉我我做错了什么吗?
答案 0 :(得分:1)
这一行使用id="btnRequest"
,但它应该是name="btnRequest"
,以便php将其作为表单变量接收,并且能够在$_POST['btnRequest']
中使用它,
<input type="submit" class="btn btn-primary btn-sm" value="Request" id="btnRequest" />
答案 1 :(得分:-1)
我没有看到您的HTML代码,所以请确保执行此操作:
private static string DrawBitmap(Bitmap bmp, int xPosition, int yPosition)
{
if (bmp == null)
throw new ArgumentNullException("bmp");
StringBuilder DataString = new StringBuilder();
//Make sure the width is divisible by 8
int loopWidth = 8 - (bmp.Width % 8);
if (loopWidth == 8)
loopWidth = bmp.Width;
else
loopWidth += bmp.Width;
//DataString.Append(string.Format("EG {0} {1} {2} {3} ", xPosition, yPosition));
DataString.Append(string.Format("EG 64 128 {0} {1} ", xPosition, yPosition));
for (int y = 0; y < bmp.Height; y++)
{
int bit = 128;
int currentValue = 0;
for (int x = 0; x < loopWidth; x++)
{
int intensity;
if (x < bmp.Width)
{
Color color = bmp.GetPixel(x, y);
intensity = 255 - ((color.R + color.G + color.B) / 3);
}
else
intensity = 0;
if (intensity >= 128)
currentValue |= bit;
bit = bit >> 1;
if (bit == 0)
{
DataString.Append(currentValue.ToString("X2"));
bit = 128;
currentValue = 0;
}
}//x
}//y
DataString.Append("\r\n");
return DataString.ToString();
}
一般来说,当我的表格表现不正常时,因为第一种表格没有提前正确关闭。这是一个很常见的错误。您可以使用相同的字段名称,只要两个表单完全独立,就没有关系。