InfinityFree主机环境下PHPMailer发送邮件报HTTP 500错误的问题求助
InfinityFree主机环境下PHPMailer发送邮件报HTTP 500错误的问题求助
我在InfinityFree主机上部署的网站,用PHPMailer发送邮件时遇到了HTTP 500错误,没有其他额外的错误提示信息。我反复检查了代码,但还是没法定位问题出在哪里。
我的代码逻辑是当用户提交邮箱地址后,调用PHPMailer发送对应类型的相册访问邮件,所有代码都放在同一个文件中,完整内容如下:
require 'phpmailer/vendor/autoload.php'; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; function send_live_album_email($email, $album_url, $qr_code_file) { return send_qr_email($email, $album_url, $qr_code_file, "Live Album Access"); } function send_longterm_album_email($email, $album_url) { $qr_code_file = ""; return send_qr_email($email, $album_url, $qr_code_file, "Long-term Album Access"); } function send_qr_email($email, $album_url, $qr_code_file) { $mail = new PHPMailer(true); $mail->IsSMTP(); $mail->SMTPDebug = 0; $mail->SMTPAuth = true; $mail->SMTPSecure = "tls"; $mail->Port = 587; $mail->Host = "smtp.gmail.com"; $mail->Username = "my_email"; // 邮箱已打码 $mail->Password = "my_password"; // 密码已打码 $mail->IsHTML(true); $mail->AddAddress($email); $mail->setFrom("my_email", "Photo Album Access | Photographer App"); // 邮件主题和内容 $mail->Subject = "Photographer | Photo Album QR Code"; $qr_code_image_url = "url_here" . htmlspecialchars($qr_code_file ?? ''); // URL已打码 $email_template = " <h2>Hello!</h2> <p>Here is your link to access the photo album:</p> <p><a type='button' class='btn btn-primary' href='$album_url'>Click here to view album</a></p> <br><br> <p>Regards,</p> <h4>Photographer App</h4> "; $mail->Body = $email_template; $mail->AltBody = strip_tags($email_template); try { $mail->send(); return true; } catch (Exception $e) { return false; } } if (isset($_POST['send_email'])) { $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL); $album_url = "url_here"; // URL已打码 if ($isLive) { if ($qr_code_file) { if (send_live_album_email($email, $album_url, $qr_code_file)) { echo "<script>alert('Live album sent successfully!');</script>"; } else { echo "<script>alert('Failed to send live album email.');</script>"; } } else { echo "<script>alert('QR code not available for live album.');</script>"; } } else { if (send_longterm_album_email($email, $album_url)) { echo "<script>alert('Album email sent successfully!');</script>"; } else { echo "<script>alert('Failed to send long-term album email.');</script>"; } } } ?> <form action="" method="post"> <div class="mb-3"> <label for="email" class="form-label">Email</label> <input type="email" name="email" id="email" class="form-control" placeholder="Enter your email here" required> </div> <button name="send_email" type="submit" class="btn btn-primary">Submit</button> </form>
备注:内容来源于stack exchange,提问作者krxshia
相关产品推荐
相关产品推荐

