首页 > 解决方案 > PHP 无法从邮件程序中获取返回值

问题描述

我的网站上有一个联系表。我想让 PHP 邮件程序工作,我从表单中获取输入并返回 1 表示成功,否则返回 -1 错误。我想包括那个,我已经收集了邮件文件。

这是我得到的错误。

注意:未定义索引:C:\xampp\htdocs\omnifood\index.php 中的成功

此 php 代码获取 mailer.php 文件返回的值。

<?php
if ($_GET['success'] == 1) {
    echo "<div class=\"form-message success\"> Thank you. Your message has been sent ! </div>";
}
if ($_GET['success'] == -1) {
    echo "<div class=\"form-message error\"> Opps! Something went wrong. Please try again. </div>";
} 
?>

这是发生任何错误时返回值的代码。

if (empty($name) OR empty($message) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
    header("Location: localhost:8080/omnifood/index.php?success=-1#form");
    exit;
}

成功发送邮件后,会返回。

header("Location: localhost:8080/omnifood/index.php?success=1#form");

标签: phpgetphpmailer

解决方案


推荐阅读