我在与phpmailer v6的联系表上需要一些帮助。我的问题ID如何将联系表单数据传递给esender.php?您的帮助将不胜感激。
**请注意,我的esender.php运行良好。现在,我只需要从表单中获取信息即可。
这是我简单的bootstrap4联系表格:
<form method="POST" action="esender.php">
<div class="form-group">
<input type="text" class="form-control" placeholder="First name" id="firstname" name="firstname">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Last name" id="name" name="name">
</div>
<div class="form-group">
<input type="email" class="form-control" id="email" placeholder="[email protected]" name="email">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="WebSite" id="website" name="website">
</div>
<div class="form-group">
<label for="FormControlSelect">Tell me about your project</label>
<select class="form-control" id="project" name="project">
<option selected value="Please select one">Please select one</option>
<option value="Web Development">Web Development</option>
<option value="e-Commerce">e-Commerce</option>
<option value="OnSite">OnSite SEO</option>
<option value="Social Media">Social Media</option>
<option value="Internet Hosting">Internet Hosting</option>
<option value="CyberSecurity">CyberSecurity</option>
<option value="Encrypted Email">Encrypted Email</option>
<option value="Technical Support">Technical Support</option>
</select>
</div>
<div class="form-group">
<label for="FormTextarea">Message</label>
<textarea class="form-control" id="themessage" rows="3" name="themessage"></textarea>
</div>
<button class="btn btn-primary submit" type="submit">Submit form</button>
</form>
这是我的esender.php
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
// Load Composer's autoloader
require 'vendor/autoload.php';
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
// Mail server configuration
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->AuthType = 'LOGIN';
$mail->Username = '[email protected]';
$mail->Password = 'password';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
$mail->CharSet = 'UTF-8';
// Recipients
$mail->SetFrom('[email protected]', 'My Name');
$mail->AddAddress('[email protected]', 'My Name');
$mail->AddReplyTo('[email protected]', 'Some Name');
// Content
$mail->IsHTML(true);
$mail->Subject = 'Test is Test Email';
//$mail->Body = 'Send HTML Email using SMTP in PHP, This is a test email I’m sending using SMTP mail server with PHPMailer.';
$mail->Body = <<<EOT
First Name: {$_POST['firstname']}
Name: {$_POST['name']}
Email: {$_POST['email']}
Website: {$_POST['website']}
Project: {$_POST['project']}
Message: {$_POST['themessage']}
EOT;
$mail->send();
echo 'Message has been sent!';
} catch (Exception $e){
echo 'Message could not be sent. Error: ', $mail->ErrorInfo;
}
?>
根据您的答案,使用POST方法获取参数。
<?php
$firstname = $_POST['firstname'];
$website = $_POST['website'];
?>
依此类推。现在,您将可以在PHP邮件程序中使用变量。