dqcuq4138 2009-12-21 17:12
浏览 52
已采纳

PHP mail()错误; 我看不出来看!

I'm having an issue with a simple PHP mailer. I've had this script working, but it now doesn't work and I can't see for the life of me why not. It's instead spitting out the raw HTML rather than the rendered template.

If someone could have a browse and get back to me then that would be great. Thanks in advance.

<?php
if (isset($_POST['send']))
{
    // explode the email addresses
    $emails = explode(',', strtolower($_POST['to']));

    // validate each email address
    foreach ($emails as $id => $email) {
        if (!filter_var(trim($email), FILTER_VALIDATE_EMAIL)) {
            die($email . ' is not a valid email address');
        }
    }

    // all is good, let's send the emails out
    $subject = 'Digital Pop Christmas Email';
    $message = file_get_contents('index.html');

    // loop through each recipient
    foreach ($emails as $email) {
        $to = $email;
        $subject = 'Merry Christmas from Digital Pop';
        $headers  = 'MIME-Version: 1.0' . "
";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";
        $headers .= 'To: ' . $email . "
";
        $headers .= 'From: Digital Pop <info@digitalpop.co.uk>' . "
";
        if (mail($to, $subject, $message, $headers)) {
            echo "Email successfully sent to $email";
        } else {
            echo "Error sending email to $email";
        }
        echo "<br />
";
    }
    exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <title>PHP Mailer</title>
    <meta http-equiv="author" content="martin@digitalpop.co.uk" />
  </head>
  <body>
    <p>Send the <a href="./">Digital Pop Christmas Email</a>.</p>
    <form action="?" method="post">
      <fieldset>
        <div><label for="to">To:</label> <small>(separate email addresses with commas)</small></div>
        <div><textarea name="to" id="to" cols="50" rows="8"></textarea></div>
        <div><input type="submit" name="send" value="Send" /></div>
      </fieldset>
    </form>
  </body>
</html>
  • 写回答

3条回答 默认 最新

  • douyueju2912 2009-12-21 17:31
    关注

    In some rare cases due to a mail server misconfiguration you need only instead of Try that out.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据