我正在尝试使用我从GitHub下载的PHPMailer(我主要是关注YT上的教程tutorial,但我也对自己进行了一些改动)但是我遇到了问题,因为我没有&#39真的收到任何邮件。没有显示错误或任何其他问题。也许有人会看到我不喜欢的东西。如果你需要了解更多问题。因为我是初学者,HTML代码可能有点乱。
<?php
session_start();
require_once 'libs/phpmailer/PHPMailerAutoload.php';
if(isset($_POST['name'], $_POST['email'], $_POST['text'])){
$fields = [
'name' => $_POST['name'],
'email' => $_POST['email'],
'text' => $_POST['text']
];
foreach($fields as $field => $data){
if(empty($data))
$errors[$field] = $field . ' is required';
}
if(empty($errors['name']) && empty($errors['email']) && empty($errors['text'])){
$m = new PHPMailer;
$m->isSMTP();
$m->SMTPAuth = true;
$m->Host = 'smtp.@gmail.com';
$m->Username = 'censored.com';
$m->Password = 'censored';
$m->SMTPsecure = 'ssl';
$m->Port = 465;
$m->isHTML();
$m->Subject = 'Contact form submitted';
$m->Body = 'From '.$fields['name'].' ('.$fields['email'].')<p>'.$fields['text'].'</p>';
$m->FromName = 'Contact';
$m->AddAddress('censored', 'James Smith');
}
}
else
$errors[] = "Something went wrong";
$_SESSION['errors'] = $errors;
$_SESSION['fields'] = $fields;
header("Location: index.php");
这是我的HTML代码
?php
session_start();
$errors = isset($_SESSION['errors']) ? $_SESSION['errors'] : [];
$fields = isset($_SESSION['fields']) ? $_SESSION['fields'] : [];
?>
<!DOCTYPE HTML>
<html charset="utf-8">
<head>
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<title>GoForward</title>
<meta name="description" content="Strona o czymś" />
<meta name="keywords" content="strona, coś, tak" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>
<script src="jquery.scrollTo.min.js"></script>
</head>
<body>
<div id="menu">
<div class="icon" id="first"></div>
<div class="icon" id="second"></div>
<div class="icon" id="third"></div>
</div>
<div id="nav">
<ul>
<a id="o1" href="#">
<li class="option">start</li>
</a>
<a id="o2" href="#">
<li class="option">about</li>
</a>
<a id="o3" href="#">
<li class="option">why us</li>
</a>
<a id="o4" href="#">
<li class="option">contact</li>
</a>
</ul>
</div>
<div id="start">
<div id="logo">
GoForward
<div id="slogan"><span>with us</span></div>
</div>
<div id="a2" class="arrow">❯</div>
</div>
<div id="about">
<h1>our mission</h3>
<div id="about_text">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur elementum risus in pretium vehicula. Vestibulum sagittis
accumsan ante non egestas. Vivamus nec sapien tincidunt, efficitur lacus eget, dapibus tellus. Quisque dignissim commodo
eleifend. Quisque risus lacus, dignissim eget turpis in, fringilla fermentum nibh. Donec efficitur ullamcorper ipsum,
eget ultricies urna euismod at. Vivamus nec ante odio. Duis dignissim pharetra elit, id congue mauris fermentum in. Nullam
eu commodo magna, at ultricies massa. Donec laoreet arcu eros, vitae vehicula nisi egestas ut. Donec porta at purus quis
mollis. Praesent eu mi justo. Etiam suscipit elit ut.
</div>
<div id="a3" class="arrow">❯</div>
</div>
<div id="why">
<h1>why us<span id="question">?</span></h1>
<div id="slider">
<img id="i3" class="slide" src="develop.jpg">
<img id="i2" class="slide" src="strefa.jpg">
<img id="i1" class="slide" src="place.jpg">
<div id="img_hover">
<div class="slider_arrow" id="left_one" onclick="plusIndex(-1)">→</div>
<p id="reason">Progress</p>
<div class="slider_arrow" id="right_one" onclick="plusIndex(1)">→</div>
</div>
<div id="img_text">
<div class="img_textx">Duis dignissim pharetra elit, id congue mauris fermentum in. Nullam eu commodo magna, at ultricies massa. Donec laoreet
arcu eros, vitae vehicula nisi egestas ut. Vivamus nec ante odio. Duis dignissim pharetra elit, id congue mauris fermentum
in. Nullam eu commodo magna, at ultricies massa.</div>
<div class="img_textx" style="display: none;">Duis dignissim pharetra elit, id congue mauris fermentum in. Nullam eu commodo magna, at ultricies massa. Donec laoreet
arcu eros, vitae vehicula nisi egestas ut. Vivamus nec ante odio. Duis dignissim pharetra elit, id congue mauris fermentum
in. Nullam eu commodo magna, at ultricies.</div>
<div class="img_textx" style="display: none;">Duis dignissim pharetra elit, id congue mauris fermentum in. Nullam eu commodo magna, at ultricies massa. Donec laoreet
arcu eros, vitae vehicula nisi egestas ut. Vivamus nec ante odio. Duis dignissim pharetra elit, id congue mauris fermentum
in. Nullam eu commodo magna.</div>
</div>
</div>
<div id="a4" class="arrow">❯</div>
</div>
<div id="contact">
<h1>Contact us</h1>
<form id="form" action="contact.php#form" method="post">
<div id="name">
<label><b>Name</b></label></br>
<input name="name" type="name"
<?php if(isset($fields['name'])) echo "value= '".$fields['name']."'"?>
<?php if(!empty($errors['name'])) echo "placeholder= '".$errors['name']."'"?>
>
</div>
<div id="email">
<label><b>E-mail</b></label></br>
<input name="email" type="email"
<?php if(isset($fields['email'])) echo "value= '".$fields['email']."'"?>
<?php if(!empty($errors['email'])) echo "placeholder= '".$errors['email']."'"?>
>
</div>
<div id="text">
<textarea name="text" <?php if(!empty($errors['text'])) echo "placeholder= '".$errors['text']."'"?>><?php if(isset($fields['text'])) echo $fields['text']?></textarea>
</div>
<input name="send" src="envelope.png" type="image">
</form>
<div id="up">❯</div>
</div>
</body>
</html>
<?php
unset($_SESSION['errors']);
unset($_SESSION['fields']);
?>
&#13;
//编辑
解决。我只需更改gmail设置即可访问未经授权的应用程序。