用于简报的PHP邮件程序不起作用

时间:2016-06-03 17:29:23

标签: php email

我写过一个用于发送简讯电子邮件的脚本,但它不起作用,我不知道为什么 这是代码:

    $subject = $_POST['subject'];
    $body = $_POST['body'];
    $headers = "From: no-reply@mywebsite.com\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    try {
        $stmt = $db->prepare("SELECT * FROM `newsletter`");
        $stmt->execute();
        foreach($stmt as $row) {
            if(mail($row['email'], $subject, $body, $headers)) {
                echo "The email to " . $row['email'] . " was <font color=\"green\">successfully sent</sent>.<br />";
            } else {
                echo "The email to " . $row['email'] . " <font color=\"red\">failed</font>.<br />";
            }
        }
    } catch (PDOException $e) {
        echo "<p><b>Sorry the connection to the database failed with: {$e->getMessage()}</b></p>";
    }

当我运行代码时,电子邮件似乎已发送,但我的邮箱是空的

提前致谢

0 个答案:

没有答案