issues/errors 使用 php 表单通过本地主机 Xampp 使用 php-mailer 库发送电子邮件
issues/errors with from php form for sending email via local host Xampp using php-mailer library
我正在尝试填写我网站上的 php 表格,并在提交表格后将表格内容发送到我的电子邮箱。我正在使用 Xampp 本地主机。所以在 "htdocs" 文件夹中有我的 "website" 文件夹以及我从 GitHub 下载的 "phpmailer" 文件夹。
在本地主机上填写表格时,我收到如下所示的警告和错误消息:
警告:要求(phpmailer/PHPMailerAutoload.php):无法打开流:第 5[=15 行 /Applications/XAMPP/xamppfiles/htdocs/websiteproject/booking.php 中没有此类文件或目录=]
致命错误:require(): Failed opening required 'phpmailer/PHPMailerAutoload.php' (include_path='.:/Applications/XAMPP/xamppfiles/lib/php') in /Applications/XAMPP/xamppfiles/htdocs/websiteproject/booking.php on第 5 行
即使我将 phpmailer 文件夹放入网站文件夹,它也不起作用。我将不胜感激使这项工作的任何帮助。非常感谢
这是我的代码:
<?php
$result="";
if (isset($_POST['submit'])) {
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->Host='smtp.gmail.com';
$smail->port=587;
$smail->SMTPAuth=true;
$mail->SMTPSecure='tls';
$mail->Username='myemail@gmail.com';
$mail->Password= 'mypassword';
$mail->setFrom($_POST['email'],$_POST['name']);
$mail->addAddress('myemail');
$mail->addReplyTo($_POST['email'],$_POST['name']);
$mail->isHTML(true);
$mail->Body= '<h1 align=center> Name :' .$_POST['name'].'<br> Email: '.$_POST['email'].'<br>
Contact: '.$_POST['contactnumber'].'<br> Date: '.$_POST['date'].'<br> Services: '.$_POST['service'].'<br>
Stylist: '.$_POST['stylist'].'</h1>';
if(!$mail->send()){
echo "Something went wrong, Please try again.";
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo "Thanks".$_POST['name']." for your booking";
}
}
?>
<!doctype html>
<html lang="en"><head>
<!-- Required meta tags -->
<title>Clypsdra Barber</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
<link href="css/style.css" rel="stylesheet" type="text/css">
<!-- awesome-font CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="css/font-awesome.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="bookingform">
<h5 "class=text-center text-success"> <?=$result; ?></h5>
<form class="testform" action="" method="post" >
<h1>Make your booking</h1>
<div class="form-group">
<label for="name">Your Name</label>
<input type="text" class="form-control" name="name" placeholder="full name">
</div>
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" name="email" placeholder="your e-mail">
</div>
<div class="form-group">
<label for="contactnumber">Contact Number</label>
<input type="number" class="form-control" name="contactnumber" placeholder="Mobile number">
</div>
<div class="form-group">
<label for="date">Book your date</label>
<input type="date" name="date" class="form-control" placeholder="">
</div>
<div class="serv">
<p>Select services:</p>
<select name="services">
<option value="s"> Please Select</option>
<option value="hc">Haircut --- £13</option>
<option value="cw">Wash + Cut £20 Clipper cut</option>
<option value="su">Shape Up --- £7</option>
<option value="bt">Beard trim --- £8</option>
<option value="cb">Cut + Beard --- £23 </option>
<option value="cc">Clipper Cut --- £10</option>
<option value="hts">Hot Towel Shave --- £12</option>
</select>
</div>
<div class="styl">
<p>Choose Stylist:</p>
<select name="stylist">
<option value="Kocher">Kocher</option>
<option value="Dyako">Dyako</option>
<option value="Omeed">Omeed</option>
<option value="Omeed">Burhan</option>
</select>
</div>
<div class="formsubmit">
<input type="checkbox" class="form-check-input" id="exampleCheck1">
<label class="form-check-label" for="exampleCheck1">Check me out</label>
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
<script>
$(document).ready(function () {
$('.first-button').on('click', function () {
$('.animated-icon1').toggleClass('open');
});
});
</script>
</body>
</html>
如果您下载了latest PHPMailer from github, it won't work with that old code, because the file you're trying to load no longer exists. Base your code on the gmail example code provided with PHPMailer。如果遇到麻烦,请阅读自述文件和其他文档。
我正在尝试填写我网站上的 php 表格,并在提交表格后将表格内容发送到我的电子邮箱。我正在使用 Xampp 本地主机。所以在 "htdocs" 文件夹中有我的 "website" 文件夹以及我从 GitHub 下载的 "phpmailer" 文件夹。
在本地主机上填写表格时,我收到如下所示的警告和错误消息:
警告:要求(phpmailer/PHPMailerAutoload.php):无法打开流:第 5[=15 行 /Applications/XAMPP/xamppfiles/htdocs/websiteproject/booking.php 中没有此类文件或目录=]
致命错误:require(): Failed opening required 'phpmailer/PHPMailerAutoload.php' (include_path='.:/Applications/XAMPP/xamppfiles/lib/php') in /Applications/XAMPP/xamppfiles/htdocs/websiteproject/booking.php on第 5 行
即使我将 phpmailer 文件夹放入网站文件夹,它也不起作用。我将不胜感激使这项工作的任何帮助。非常感谢
这是我的代码:
<?php
$result="";
if (isset($_POST['submit'])) {
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->Host='smtp.gmail.com';
$smail->port=587;
$smail->SMTPAuth=true;
$mail->SMTPSecure='tls';
$mail->Username='myemail@gmail.com';
$mail->Password= 'mypassword';
$mail->setFrom($_POST['email'],$_POST['name']);
$mail->addAddress('myemail');
$mail->addReplyTo($_POST['email'],$_POST['name']);
$mail->isHTML(true);
$mail->Body= '<h1 align=center> Name :' .$_POST['name'].'<br> Email: '.$_POST['email'].'<br>
Contact: '.$_POST['contactnumber'].'<br> Date: '.$_POST['date'].'<br> Services: '.$_POST['service'].'<br>
Stylist: '.$_POST['stylist'].'</h1>';
if(!$mail->send()){
echo "Something went wrong, Please try again.";
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo "Thanks".$_POST['name']." for your booking";
}
}
?>
<!doctype html>
<html lang="en"><head>
<!-- Required meta tags -->
<title>Clypsdra Barber</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
<link href="css/style.css" rel="stylesheet" type="text/css">
<!-- awesome-font CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="css/font-awesome.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="bookingform">
<h5 "class=text-center text-success"> <?=$result; ?></h5>
<form class="testform" action="" method="post" >
<h1>Make your booking</h1>
<div class="form-group">
<label for="name">Your Name</label>
<input type="text" class="form-control" name="name" placeholder="full name">
</div>
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" name="email" placeholder="your e-mail">
</div>
<div class="form-group">
<label for="contactnumber">Contact Number</label>
<input type="number" class="form-control" name="contactnumber" placeholder="Mobile number">
</div>
<div class="form-group">
<label for="date">Book your date</label>
<input type="date" name="date" class="form-control" placeholder="">
</div>
<div class="serv">
<p>Select services:</p>
<select name="services">
<option value="s"> Please Select</option>
<option value="hc">Haircut --- £13</option>
<option value="cw">Wash + Cut £20 Clipper cut</option>
<option value="su">Shape Up --- £7</option>
<option value="bt">Beard trim --- £8</option>
<option value="cb">Cut + Beard --- £23 </option>
<option value="cc">Clipper Cut --- £10</option>
<option value="hts">Hot Towel Shave --- £12</option>
</select>
</div>
<div class="styl">
<p>Choose Stylist:</p>
<select name="stylist">
<option value="Kocher">Kocher</option>
<option value="Dyako">Dyako</option>
<option value="Omeed">Omeed</option>
<option value="Omeed">Burhan</option>
</select>
</div>
<div class="formsubmit">
<input type="checkbox" class="form-check-input" id="exampleCheck1">
<label class="form-check-label" for="exampleCheck1">Check me out</label>
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
<script>
$(document).ready(function () {
$('.first-button').on('click', function () {
$('.animated-icon1').toggleClass('open');
});
});
</script>
</body>
</html>
如果您下载了latest PHPMailer from github, it won't work with that old code, because the file you're trying to load no longer exists. Base your code on the gmail example code provided with PHPMailer。如果遇到麻烦,请阅读自述文件和其他文档。