我是网络开发的新手。我编写了一个 php 代码来从表单发送电子邮件,并将其托管在 cloudways 中。每当我点击提交按钮时,我都会收到 HTTP ERROR 500。
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
# code...
$name = trim($_POST["fullname"]);
$email = trim($_POST["email"]);
$phone_no = trim($_POST["phone_num"]);
$partner_type = $_POST["Partner_type"];
if ($name == "" || $email == "" || $phone_no == " ") {
echo "please fill the required fields name , email , phone number";
}
if ($_POST["adds"] != "") {
echo "Bad form input";
exit;
}
require 'class.phpmailer.php';
$mail = new PHPMailer();
if (!$mail->ValidateAddress($email)) {
# code...
echo "Invalid Email Address";
exit;
}
$email_body = "";
$email_body .= "Name " . $name . "\n";
$email_body .= "Email " . $email . "\n";
$email_body .= "Phone Number " . $phone_no . "\n";
$email_body .= "Partner Type " . $partner_type . "\n";
$mail->setFrom($email, $name);
$mail->addAddress('rescuetl@localhost', 'gbubemi'); // Add a recipient
/**$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
**/
$mail->isHTML(false); // Set email format to HTML
$mail->Subject = 'Become a Partner ' . $name ;
$mail->Body = $email_body;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
} else {
echo 'Message has been sent';
}
header("location:index.php?status=thanks");
}
?>
拜托这真的很令人沮丧,我需要帮助。谢谢。