问题PHP Mailer [英] Problem PHP Mailer

查看:73
本文介绍了问题PHP Mailer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PHP Mailer制作了联系表格,该代码基于PHPMailer测试邮件,效果很好.

I made an contact form using PHP Mailer, the code is based on the PHPMailer test mail which worked fine.

但是现在它只是不会发送我的电子邮件,它一直向我显示错误.代替Verzonden(已发送)

But now it just won't send my email, it keeps showing me wrong. Instead of Verzonden (Sended)

这是我的代码

<?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>

推荐答案

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

It's good you're checking if the $mail->send() works or not, but you're throwing away the error messages when it fails, which isn't good:

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

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

However, you don't say how it's not sending the mail. PHP Mailer only hands off the mail to whatever mail server it's configured to use. The mail can still fail later on for other reasons, so if the $mail->send() succeeds, then you'll have to check the mail server's logs.

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

Your server may have been blacklisted, or otherwise flagged as a spam source.

这篇关于问题PHP Mailer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆