PHP邮件没有通过

时间:2012-08-18 17:25:48

标签: email php

我试图将联系人从我的网站邮寄到我的hotmail帐户,但它似乎没有通过,它甚至没有出现在垃圾邮件中,我会在这里发布我的代码也许有人知道如何调整它(至少)进入我的垃圾邮件。

我也不想使用任何php邮件服务或类似的东西,所以请不要建议。

编辑:工作代码(使用phpMailer)

    <?php
require_once('phpmailer/class.phpmailer.php');
define('GUSER', 'youtGmail@gmail.com); // GMail username
define('GPWD', 'gmailPassword'); // GMail password

    function smtpmailer($to, $from, $from_name, $subject, $body) { 
        global $error;
        $mail = new PHPMailer();  // create a new object
        $mail->IsSMTP(); // enable SMTP
        $mail->SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only
        $mail->SMTPAuth = true;  // authentication enabled
        $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
        $mail->Host = 'smtp.gmail.com';
        $mail->Port = 465; 
        $mail->Username = GUSER;  
        $mail->Password = GPWD;           
        $mail->SetFrom($from, $from_name);
        $mail->Subject = $subject;
        $mail->Body = $body;
        $mail->AddAddress($to);
            if(!$mail->Send()) {
                $error = 'Mail error: '.$mail->ErrorInfo; 
                return false;
            } else {
                $error = 'Message sent!';
                return true;
            }
    }

if(isset($_POST['submit'])) {


    if(trim($_POST['contactname']) == '') {
        $hasError = true;
    } else {
        $name = trim($_POST['contactname']);
    }


    if(trim($_POST['subject']) == '') {
        $hasError = true;
    } else {
        $subject = trim($_POST['subject']);
    }


    if(trim($_POST['email']) == '')  {
        $hasError = true;
    } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
        $hasError = true;
    } else {
        $email = trim($_POST['email']);
    }


    if(trim($_POST['message']) == '') {
        $hasError = true;
    } else {
        if(function_exists('stripslashes')) {
            $comments = stripslashes(trim($_POST['message']));
        } else {
            $comments = trim($_POST['message']);
        }
    }


    if(!isset($hasError)) {

     $emailTo = 'your@email.com';
     smtpmailer($emailTo, $email, 'Company', $name, $subject, $comments);
     $emailSent = true;

    }
}
?>

编辑:我被建议使用SMTP,但我不确定如何实现。

2 个答案:

答案 0 :(得分:0)

您从哪个域发送电子邮件?受信任的.com还是电子邮件服务器可能识别为垃圾邮件?像这样的域通常是免费的。

如果没有,我会检查你的php.ini文件,以确保它是properly configured

答案 1 :(得分:0)

您可以尝试多种方法来改善电子邮件接收效果。您可以尝试使用域密钥设置X-mailer标头,如果所有其他方法都失败,只需从google smtp帐户发送邮件即可。我强烈建议使用谷歌smtp帐户+像PHP邮件程序。我对这个解决方案没有任何问题。

这是一个关于如何使用gmail + phpmailer通过smtp发送邮件的教程:

http://www.web-development-blog.com/archives/send-e-mail-messages-via-smtp-with-phpmailer-and-gmail/

相关问题