问题PHP邮件程序

时间:2011-04-15 19:33:07

标签: php phpmailer

我使用PHP Mailer创建了一个联系表单,代码基于PHPMailer测试邮件,工作正常。

但现在它不会发送我的电子邮件,它一直让我错了。而不是Verzonden(已发送)

这是我的代码

<?php
require("CMS/scripts/phpmailer/phpmailer.inc.php");

if (isset($_POST) && !empty($_POST) && $_POST['post_form'] == "contact") {
    $mail = new phpmailer;

    print_pre($_POST);

    $mail->IsSMTP(); // set mailer to use SMTP
//  $mail->From = $_POST['email'];
    $mail->FromName = $_POST['voornaam']."&nbsp;".$_POST['achternaam'];
    $mail->Host = "mail.chello.nl";  // this is my smtp server from my provider
    $mail->AddAddress("mail@to.com");
//  $mail->AddReplyTo("reply@mail.com", "Reply");

    $mail->IsHTML(true);    // set email format to HTML
    $mail->Subject = $_POST['onderwerp'];
    $mail->Body = "
    <div id='mail'>
        <table>
            <tr>
                <td colspan='2'><h2>".$_POST['onderwerp']."</h2></td>
            </tr>
            <tr>
                <td>Naam</td>
                <td>".$_POST['voornaam']."&nbsp;".$_POST['achternaam']."</td>
            </tr>
            <tr>
                <td>Adres</td>
                <td>".$_POST['adres']."</td>
            </tr>
            <tr>
                <td>Postcode + Woonplaats</td>
                <td>".$_POST['postcode']."&nbsp;".$_POST['woonplaats']."</td>
            </tr>
            <tr>
                <td>Telefoon</td>
                <td>".$_POST['telefoon']."</td>
            </tr>
            <tr>
                <td>E-mail</td>
                <td>".$_POST['email']."</td>
            </tr>
            <tr>
                <td>Onderwerp</td>
                <td>".$_POST['onderwerp']."</td>
            </tr>
            <tr>
                <td colspan='2'>Bericht</td>
            </tr>
            <tr>
                <td colspan='2'>".$_POST['bericht']."</td>
            </tr>    
    </div>
    ";
    if ($mail->Send()) {
        echo "Verzonden";
    } else {        
        echo "wrong";
    }
}
?>
<div id="contact_form">
    <form action="#" method="post">
    <input type="hidden" value="contact" name="post_form">
    <table>
        <tr>
            <td>Naam</td>
            <td><input type="text" name="voornaam" class="contact_inputfield"></td>
            <td><input type="text" name="achternaam" class="contact_inputfield"></td>
        </tr>
        <tr>
            <td>Adres</td>
            <td colspan="2"><input type="text" name="adres" class="contact_inputfield_double"></td>
        </tr>
        <tr>
            <td>Postcode + Woonplaats</td>
            <td><input type="text" name="postcode" class="contact_inputfield"></td>
            <td><input type="text" name="woonplaats" class="contact_inputfield"></td>
        </tr>
        <tr>
            <td>Telefoon</td>
            <td colspan="2"><input type="text" name="telefoon" class="contact_inputfield_double"></td>
        </tr>
        <tr>
            <td>E-mail</td>
            <td colspan="2"><input type="text" name="email" class="contact_inputfield_double"></td>
        </tr>
        <tr>
            <td>Onderwerp</td>
            <td colspan="2"><input type="text" name="onderwerp" class="contact_inputfield_double"></td>
        </tr>
        <tr>
            <td valign="top">Bericht</td>
            <td colspan="2"><textarea name="bericht" class="contact_textarea"></textarea> </td>
        </tr>
        <tr>        
            <td colspan="3"><input type="submit" value="Verzenden" class="contact_send"></td>
        </tr>
    </table>
    </form>
</div>

1 个答案:

答案 0 :(得分:2)

你检查$mail->send()是否有效是好的,但是当它失败时你会丢失错误消息,这是不好的:

if ($mail->Send()) {
    echo "Verzonden";
} else {        
    echo "failed: " . $mail->ErrorInfo;
}

但是,您没有说它是如何发送邮件的。 PHP Mailer只将邮件传递给它配置使用的任何邮件服务器。由于其他原因,邮件以后仍可能失败,因此如果$mail->send()成功,则您必须检查邮件服务器的日志。

您的服务器可能已被列入黑名单,或被标记为垃圾邮件来源。