从php表单使用php-mailer库通过本地主机Xampp发送电子邮件的问题/错误

时间:2019-02-14 16:04:07

标签: php xampp phpmailer

我正在尝试填写我在网站上拥有的php表单,并在提交表单时将表单的内容发送到我的电子邮件中。我正在使用Xampp本地主机。因此,在“ htdocs”文件夹中,有我的“网站”文件夹以及从GitHub下载的“ phpmailer”文件夹。

在本地主机上,当我填写表格时,会收到警告和错误消息,如下所示:

警告:require(phpmailer / PHPMailerAutoload.php):无法打开流:在第5行的/Applications/XAMPP/xamppfiles/htdocs/websiteproject/booking.php中没有此类文件或目录

致命错误:require():无法在/ Applications / XAMPP / xamppfiles / htdocs / websiteproject /中打开所需的'phpmailer / PHPMailerAutoload.php'(include_path ='。:/ Applications / XAMPP / xamppfiles / lib / php') 5号线上的booking.php

即使我将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 &#43; 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>

1 个答案:

答案 0 :(得分:0)

如果您下载了latest PHPMailer from github,它将无法使用该旧代码,因为您尝试加载的文件已不存在。您的代码基于the gmail example code provided with PHPMailer。如果遇到麻烦,请阅读自述文件和其他文档。