【发布时间】:2020-09-30 07:10:11
【问题描述】:
我试图弄清楚如何检索选择的下拉列表并使用 PHPmailer 将其发送到邮件,但我无法实现它,它只需要一些调整!另请注意,我将 Bulma 用作我项目的一部分。
<form action="bug.php" method="POST" class="" enctype="multipart/form-data">
<div class="section">
<div class="container">
<div class="columns">
<div class="column"></div>
<div class="column is-5">
<div class="field">
<label class="label">Name</label>
<div class="control">
<input
class="input"
type="text"
id="name"
name="vname"
placeholder="e.g Alex Smith"
/>
</div>
</div>
<div class="field">
<label class="label">Email</label>
<div class="control">
<input
class="input"
type="email"
name="vemail"
placeholder="e.g. alexsmith@gmail.com"
/>
</div>
</div>
<div class="control">
<div class="select">
<select id="selection" onchange="showradio(this)">
<option value="0">Select dropdown</option>
<option value="1">Best</option>
<option value="2">Bestest</option>
<option value="3">Exceptional</option>
</select>
</div>
</div>
<div class="buttons" >
<button name="btnsubmit" id="btnsend" class="button is-primary is-light">Submit</button>
</div>
</div>
<div class="column"></div>
</div>
</div>
</div>
</form>
现在是我配置的 PHPMailer。
<?php
$name = $_POST['vname'];
$email = $_POST['vemail'];
$msg = $_POST['vmsg'];
// 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 'PHPmailer/vendor/autoload.php';
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'from24@gmail.com'; // SMTP username
$mail->Password = 'pass'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('messagefrom24@gmail.com', 'Tools');
$mail->addAddress('messageto@gmail.com', 'To'); // Add a recipient
$mail->AddAddress("$_POST['emailreceiver']");
// // Attachments
// $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'New Bug Submission !';
$mail->Body = $msg;
// $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>
代码仅发送消息、主题和名称,但我需要添加在下拉列表中选择的文本。
【问题讨论】:
-
在您的选择标签中添加 name="dropdown" 然后通过 $_POST['dropdown'] 获取,而不是 value="0,1,2 将其更改为要发送的字符串
标签: javascript php html phpmailer