我正在尝试使用PHPMailer发送电子邮件,并从我网站上的Contact-Formular发送数据,但这不起作用。
我已经尝试使用用户说对他们有用的代码,但这对我也不起作用。
check_contact_form.php
<?php
session_start();
if(isset($_POST['Name']) && isset($_POST['E-Mail'])
&& isset($_POST['Anliegen']) &&!empty($_POST['Name'])
&& !empty($_POST['E-Mail']) && !empty($_POST['Anliegen'])) {
$Name = $_POST['Name'];
$Telefonnummer = "-";
if(isset($_POST['Telefonnummer'])
&& !empty($_POST['Telefonnummer'])) {
if(is_numeric($_POST['Telefonnummer'])) {
$Telefonnummer = $_POST['Telefonnummer'];
} else {
$_SESSION['errorMsg'] = 'Die eingegebene Nummer besteht
nicht nur aus Zahlen!';
header('Location: contact.php');
}
}
require_once('PHPMailer/PHPMailerAutoload.php');
$mail = new PHPMailer(true);
$mail->isSMTP();
$email_body = "";
$email_body = $email_body . "Name: " . $Name . "<br>";
$email_body = $email_body . "Email: " . $_POST['E-Mail'] . "<br>";
$email_body = $email_body . "Message: " . $_POST['Anliegen'];
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "STARTTLS";
$mail->Host = "SMTP.office365.com";
$mail->Port = 587;
$mail->Username = "my-email";
$mail->Password = "my-password";
$mail->SetFrom($_POST['E-Mail'], $Name);
$address = "my-email";
$mail->AddAddress($address);
$mail->Subject = "Anliegen per Website " . $Name;
$mail->IsHTML(true);
$mail->Body = $email_body;
if($mail->Send()) {
$_SESSION['errorMsg'] = 'Sie haben nicht alle Felder mit
einem Stern ausgefüllt!';
header('Location: contact.php');
exit;
} else {
$error_message = "Ein Fehler ist aufgetreten: " .
$mail->ErrorInfo;
}
} else {
$_SESSION['errorMsg'] = 'Sie haben nicht alle Felder mit einem
Stern ausgefüllt!';
header('Location: contact.php');
}
?>
contact.php
<form action="check_contact_form.php" method="post">
<div style="margin-left:50px; width:700px; height:100px;">
<span style="color:#F00;">*</span>Ihr Vor- und Nachname:<br>
<input name="Name" type="text" required="required"
style="width:700px; height:35px; font-size:18px;"/>
</div>
<div style="margin-left:50px; width:700px; height:100px;">
<span style="color:#F00;">*</span>Ihre E-Mail-Adresse:<br>
<input name="E-Mail" type="email" required="required"
style="width:700px; height:35px; font-size:18px;"/>
</div>
<div style="margin-left:50px; width:700px; height:100px;">
Ihre Telefonnummer:<br>
<input name="Telefonnummer" type="text" style="width:700px;
height:35px; font-size:18px;"/>
</div>
<div style="margin-left:50px; width:700px; height:100px;">
<span style="color:#F00;">*</span>Ihre Anliegen:<br>
<textarea name="Anliegen" type="text" required="required"
style="width:700px; height:200px; font-size:18px;"></textarea>
<br><br>
<input style="width:150px; height:45px; font-size:20px; font-
weight:bold; background-color:#4E72D7; border:0px; color:#FFF;"
type="submit" value="Absenden"/>
</div>
</form>
致命错误:未捕获的异常'phpmailerException'和消息'SMTP错误:数据不被接受。在C:\ xampp \ htdocs \ taxi \ PHPMailer \ class.phpmailer.php:1569中的堆栈跟踪:#0 C:\ xampp \ htdocs \ taxi \ PHPMailer \ class.phpmailer.php(1335):PHPMailer-> smtpSend('日期:周四,18 J ...','名称:Marko Laz ...')#1 C:\ xampp \ htdocs \ taxi \ PHPMailer \ class.phpmailer.php(1213):PHPMailer-> postSend()# 2 C:\ xampp \ htdocs \ taxi \ check_contact_form.php(60):PHPMailer-> send()#3 {main}在1569行的C:\ xampp \ htdocs \ taxi \ PHPMailer \ class.phpmailer.php中抛出< / p>