我需要你的帮助。 我在PHPMailer库(版本6.1)的帮助下为网站创建了联系表格。如何更正代码,以便不出现错误(如下),以及如何从单独的php文件中以表格形式运行此php代码。预先感谢您的帮助。
注意:未定义的索引:第74行的C:\ xampp \ htdocs \ Test \ e-mail2 \ index.php中的附件文件
和
$mail->AddAttachment($_FILES['attachmentFile']['tmp_name'],$_FILES['attachmentFile']['name']);
注意:未定义的索引:第66行的C:\ xampp \ htdocs \ Test \ e-mail2 \ index.php中的userEmail 注意:第66行上的C:\ xampp \ htdocs \ Test \ e-mail2 \ index.php中未定义的索引:userName
$mail->SetFrom($_POST["userEmail"], $_POST["userName"]);
<body>
<form id="frmContact" action="" method="post">
<div id="mail-status"></div>
<div>
<label style="padding-top: 20px;">Name</label> <span
id="userName-info" class="info"></span><br />
<input type="text" name="userName" id="userName" class="demoInputBox">
</div>
<div>
<label>Email</label> <span id="userEmail-info" class="info"></span><br />
<input type="text" name="userEmail" id="userEmail" class="demoInputBox">
</div>
<div>
<label>Attachment</label><br />
<input type="file" name="attachmentFile" id="attachmentFile" class="demoInputBox">
</div>
<div>
<label>Subject</label> <span id="subject-info" class="info"></span><br />
<input type="text" name="subject" id="subject" class="demoInputBox">
</div>
<div>
<label>Content</label> <span id="content-info" class="info"></span><br />
<textarea name="content" id="content" class="demoInputBox" cols="60" rows="6"></textarea>
</div>
<div>
<input type="submit" value="Send" class="btnAction" />
</div>
</form>
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail->Username = "serwer1999.home.pl";
$mail->Password = "password";
$mail->Host = "serwer1999";
$mail->Mailer = "smtp";
$mail->SetFrom($_POST["userEmail"], $_POST["userName"]);
$mail->AddReplyTo($_POST["userEmail"], $_POST["userName"]);
$mail->AddAddress("agniecha@agamazur.pl");
$mail->Subject = $_POST["subject"];
$mail->WordWrap = 80;
$mail->MsgHTML($_POST["content"]);
if(is_array($_FILES)) {
$mail->AddAttachment($_FILES['attachmentFile']['tmp_name'],$_FILES['attachmentFile']['name']);
}
$mail->IsHTML(true);
$mail->send();
echo "Successful";
} catch (Exception $e) {
echo "Ups :( {$mail->ErrorInfo}";
}
?>
</body>```