我的 PHP 邮件程序代码出现 HTTP 500 错误
My PHP Mailer Code is giving a HTTP 500 error
我为一个使用普通文本框、下拉选项框、日期日历、复选框和附件的网站编制了一份详细的申请表。我只使用普通的 PHP 就可以很好地通过电子邮件发送表单,但是在处理附件部分时我卡住了。然后我学会了最好地使用 PHP Mailer 所以我为此重新做了 PHP 但得到了可怕的 HTTP 500 错误。请有人检查我的代码,看看我哪里出错了。非常感谢您。
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'href="/PHPMailer/src/Exception.php"';
require 'href="/PHPMailer/src/PHPMailer.php"';
$message = '';
function clean_text($string)
{
$string = trim($string);
$string = stripslashes($string);
$string = htmlspecialchars($string);
return $string;
}
if(isset($_POST["submit"]))
{
$path = 'href="/upload/"' . $_FILES["attachment"]["name"];
move_uploaded_file($_FILES["attachment"]["tmp_name"], $path);
$message = '
<h3 align="center">Application Details</h3>
<table border="1" width="100%" cellpadding="5" cellspacing="5">
<tr>
<td width="30%">First Name</td>
<td width="70%">'.$_POST["first_name"].'</td>
</tr>
<tr>
<td width="30%">Last Name</td>
<td width="70%">'.$_POST["last_name"].'</td>
</tr>
<tr>
<td width="30%">Email Address</td>
<td width="70%">'.$_POST["email"].'</td>
</tr>
<tr>
<td width="30%">Phone Number</td>
<td width="70%">'.$_POST["phone_number"].'</td>
</tr>
<tr>
<td width="30%">Position</td>
<td width="70%">'.$_POST["position"].'</td>
</tr>
<tr>
<td width="30%">WhatsApp Number</td>
<td width="70%">'.$_POST["whatsapp_no"].'</td>
</tr>
<tr>
<td width="30%">Yacht Name</td>
<td width="70%">'.$_POST["yacht_name"].'</td>
<tr>
<td width="30%">Yacht Type</td>
<td width="70%">'.$_POST["yacht_type"].'</td>
</tr>
<tr>
<td width="30%">Yacht Size</td>
<td width="70%">'.$_POST["yacht_size"].'</td>
</tr>
<tr>
<td width="30%">Cruising Type</td>
<td width="70%">'.$_POST["cruising_type"].'</td>
</tr>
<tr>
<td width="30%">Yacht Location</td>
<td width="70%">'.$_POST["yacht_location"].'</td>
</tr>
<tr>
<td width="30%">Yacht Itinenary</td>
<td width="70%">'.$_POST["yacht_itinenary"].'</td>
</tr>
<tr>
<td width="30%">Work Posistion</td>
<td width="70%">'.$_POST["work_position"].'</td>
</tr>
<tr>
<td width="30%">Work Type</td>
<td width="70%">'.$_POST["work_type"].'</td>
</tr>
<tr>
<td width="30%">Start Date</td>
<td width="70%">'.$_POST["start_date"].'</td>
</tr>
<tr>
<td width="30%">Finish Date</td>
<td width="70%">'.$_POST["finishing_date"].'</td>
<tr>
<td width="30%">Visa Required</td>
<td width="70%">'.$_POST["visa_req"].'</td>
</tr>
<tr>
<td width="30%">Qualifications Required</td>
<td width="70%">'.$_POST["qual_req"].'</td>
</tr>
<tr>
<td width="30%">Job Description</td>
<td width="70%">'.$_POST["job_desc"].'</td>
</tr>
<tr>
<td width="30%">Shared Cabin</td>
<td width="70%">'.$_POST["shared_cabin"].'</td>
</tr>
<tr>
<td width="30%">Understood Terms</td>
<td width="70%">'.$_POST["terms"].'</td>
</tr>
<tr>
<td width="30%">Confidental</td>
<td width="70%">'.$_POST["confidential"].'</td>
</tr>
</table>
';
if (isset($_POST['shared_cabin'])){
$_POST['shared_cabin']; // Displays value of checked checkbox.
}
if (isset($_POST['terms'])){
$_POST['terms']; // Displays value of checked checkbox.
}
if (isset($_POST['confidential'])){
$_POST['confidential']; // Displays value of checked checkbox.
}
require 'class/class.phpmailer.php';
$mail = new PHPMailer(TRUE);
$mail->From = $_POST["email_from"]; //Sets the From email address for
the message
$mail->FromName = $_POST["first_name"]["last_name"]; //Sets the From
name of the message
$mail->AddAddress('timmy2872@gmail.com'); //Adds a "To" address
$mail->WordWrap = 50; //Sets word wrapping on the body of the
message to a given number of characters
$mail->IsHTML(true); //Sets message type to HTML
$mail->AddAttachment($path); //Adds an attachment from a path on the
filesystem
$mail->Subject = 'Employer Application Form details'; //Sets the
Subject of the message
$mail->Body = $message; //An HTML or plain text message body
if($mail->Send()) //Send an Email. Return true on success or false
on error
{
$message = '<div class="alert alert-success">Application Successfully
Submitted</div>';
unlink($path);
}
else
{
$message = '<div class="alert alert-danger">There is an Error</div>';
}
}
?>
一切都已修复,现在一切如梦如幻。
问题是,我正在使用的站点位于 "Temp" 文件夹中,以免扰乱旧站点。我在子目录中有 PHPMailer 和 Upload 文件夹,而不是服务器的主目录,所以这就是它需要的方式 -
require "/home/awolpm/PHPMailer/src/Exception.php";
require "/home/awolpm/PHPMailer/src/PHPMailer.php";
也不需要这一行 -
require 'class/class.phpmailer.php';
上传文件夹需要-
$path = '/home/awolpm/upload/"' . $FILES["attachment"]["name"];
move_uploaded_file($FILES["attachment"]["tmp_name"], $path);
确实让我挠了挠头!
最后要做的一件事 - 在发送成功时弹出模式框,并return向发件人发送一封确认电子邮件。
我为一个使用普通文本框、下拉选项框、日期日历、复选框和附件的网站编制了一份详细的申请表。我只使用普通的 PHP 就可以很好地通过电子邮件发送表单,但是在处理附件部分时我卡住了。然后我学会了最好地使用 PHP Mailer 所以我为此重新做了 PHP 但得到了可怕的 HTTP 500 错误。请有人检查我的代码,看看我哪里出错了。非常感谢您。
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'href="/PHPMailer/src/Exception.php"';
require 'href="/PHPMailer/src/PHPMailer.php"';
$message = '';
function clean_text($string)
{
$string = trim($string);
$string = stripslashes($string);
$string = htmlspecialchars($string);
return $string;
}
if(isset($_POST["submit"]))
{
$path = 'href="/upload/"' . $_FILES["attachment"]["name"];
move_uploaded_file($_FILES["attachment"]["tmp_name"], $path);
$message = '
<h3 align="center">Application Details</h3>
<table border="1" width="100%" cellpadding="5" cellspacing="5">
<tr>
<td width="30%">First Name</td>
<td width="70%">'.$_POST["first_name"].'</td>
</tr>
<tr>
<td width="30%">Last Name</td>
<td width="70%">'.$_POST["last_name"].'</td>
</tr>
<tr>
<td width="30%">Email Address</td>
<td width="70%">'.$_POST["email"].'</td>
</tr>
<tr>
<td width="30%">Phone Number</td>
<td width="70%">'.$_POST["phone_number"].'</td>
</tr>
<tr>
<td width="30%">Position</td>
<td width="70%">'.$_POST["position"].'</td>
</tr>
<tr>
<td width="30%">WhatsApp Number</td>
<td width="70%">'.$_POST["whatsapp_no"].'</td>
</tr>
<tr>
<td width="30%">Yacht Name</td>
<td width="70%">'.$_POST["yacht_name"].'</td>
<tr>
<td width="30%">Yacht Type</td>
<td width="70%">'.$_POST["yacht_type"].'</td>
</tr>
<tr>
<td width="30%">Yacht Size</td>
<td width="70%">'.$_POST["yacht_size"].'</td>
</tr>
<tr>
<td width="30%">Cruising Type</td>
<td width="70%">'.$_POST["cruising_type"].'</td>
</tr>
<tr>
<td width="30%">Yacht Location</td>
<td width="70%">'.$_POST["yacht_location"].'</td>
</tr>
<tr>
<td width="30%">Yacht Itinenary</td>
<td width="70%">'.$_POST["yacht_itinenary"].'</td>
</tr>
<tr>
<td width="30%">Work Posistion</td>
<td width="70%">'.$_POST["work_position"].'</td>
</tr>
<tr>
<td width="30%">Work Type</td>
<td width="70%">'.$_POST["work_type"].'</td>
</tr>
<tr>
<td width="30%">Start Date</td>
<td width="70%">'.$_POST["start_date"].'</td>
</tr>
<tr>
<td width="30%">Finish Date</td>
<td width="70%">'.$_POST["finishing_date"].'</td>
<tr>
<td width="30%">Visa Required</td>
<td width="70%">'.$_POST["visa_req"].'</td>
</tr>
<tr>
<td width="30%">Qualifications Required</td>
<td width="70%">'.$_POST["qual_req"].'</td>
</tr>
<tr>
<td width="30%">Job Description</td>
<td width="70%">'.$_POST["job_desc"].'</td>
</tr>
<tr>
<td width="30%">Shared Cabin</td>
<td width="70%">'.$_POST["shared_cabin"].'</td>
</tr>
<tr>
<td width="30%">Understood Terms</td>
<td width="70%">'.$_POST["terms"].'</td>
</tr>
<tr>
<td width="30%">Confidental</td>
<td width="70%">'.$_POST["confidential"].'</td>
</tr>
</table>
';
if (isset($_POST['shared_cabin'])){
$_POST['shared_cabin']; // Displays value of checked checkbox.
}
if (isset($_POST['terms'])){
$_POST['terms']; // Displays value of checked checkbox.
}
if (isset($_POST['confidential'])){
$_POST['confidential']; // Displays value of checked checkbox.
}
require 'class/class.phpmailer.php';
$mail = new PHPMailer(TRUE);
$mail->From = $_POST["email_from"]; //Sets the From email address for
the message
$mail->FromName = $_POST["first_name"]["last_name"]; //Sets the From
name of the message
$mail->AddAddress('timmy2872@gmail.com'); //Adds a "To" address
$mail->WordWrap = 50; //Sets word wrapping on the body of the
message to a given number of characters
$mail->IsHTML(true); //Sets message type to HTML
$mail->AddAttachment($path); //Adds an attachment from a path on the
filesystem
$mail->Subject = 'Employer Application Form details'; //Sets the
Subject of the message
$mail->Body = $message; //An HTML or plain text message body
if($mail->Send()) //Send an Email. Return true on success or false
on error
{
$message = '<div class="alert alert-success">Application Successfully
Submitted</div>';
unlink($path);
}
else
{
$message = '<div class="alert alert-danger">There is an Error</div>';
}
}
?>
一切都已修复,现在一切如梦如幻。 问题是,我正在使用的站点位于 "Temp" 文件夹中,以免扰乱旧站点。我在子目录中有 PHPMailer 和 Upload 文件夹,而不是服务器的主目录,所以这就是它需要的方式 -
require "/home/awolpm/PHPMailer/src/Exception.php";
require "/home/awolpm/PHPMailer/src/PHPMailer.php";
也不需要这一行 -
require 'class/class.phpmailer.php';
上传文件夹需要-
$path = '/home/awolpm/upload/"' . $FILES["attachment"]["name"];
move_uploaded_file($FILES["attachment"]["tmp_name"], $path);
确实让我挠了挠头!
最后要做的一件事 - 在发送成功时弹出模式框,并return向发件人发送一封确认电子邮件。