0

我正在使用 phpMailer 设计一个简单的联系我们表单。数据正确地传递给 PHP,但电子邮件永远不会发送。我尝试查看错误信息,但它是空的。有什么想法吗?提前致谢!

<?php

    require_once('email/mail/class.phpmailer.php');

    $email_to = 'myEmail';
    $email_subject = 'Contact form';    

    $fname = $_POST['firstname'];
    $lname = $_POST['lastname'];
    $email = $_POST['email'];
    $dob = $_POST['dob'];
    $subject = $_POST['subject'];
    $comments = $_POST['comments'];

    $mailer = new PHPMailer(true);
    $mailer->Host = '**********';
    $mailer->Username = '********';
    $mailer->Password = '*********';
    $mailer->SMTPAuth = true;
    $mailer->AddAddress($email_to);
    $mailer->SMTPDebug = false;
    $mailer->IsSMTP();
    $mailer->FromName = 'Contact Page';
    $mailer->From = "**********";
    $mailer->Sender = '**********';
    $mailer->Subject = $email_subject;
    $mailer->Body = "
        Source: Contact Page
        Name: ".$fname. " ".$lname."
        Email: ".$email."
        Date of Birth: ".$dob."
        Subject: ".$subject."
        Comments: ".$comments;

    echo "Data received";

    if(!$mailer->Send()) {
        echo 'Message was not sent.';
        echo 'Mailer error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message has been sent.';
    }

?>

输出是:

Data receivedMessage was not sent.Mailer error: 

输出print_r($mailer)

PHPMailer Object ( 
    [Priority] => 3 
    [CharSet] => iso-8859-1 
    [ContentType] => text/plain 
    [Encoding] => 8bit 
    [ErrorInfo] => 
    [From] => contact@blah.com 
    [FromName] => Contact Page 
    [Sender] => contact@blah.com 
    [Subject] => Contact form 
    [Body] => 
        Source: blah 
        Name: Derp McDerpson 
        Email: derpallday@gmail.com 
        Date of Birth: 1/1/2000 
        Subject: The things! 
        Comments: fix them 
    [AltBody] => 
    [WordWrap] => 0 
    [Mailer] => smtp 
    [Sendmail] => /usr/sbin/sendmail 
    [PluginDir] => 
    [Version] => 1.73 
    [ConfirmReadingTo] => 
    [Hostname] => 
    [Host] => mail.authsmtp.com 
    [Port] => 25 
    [Helo] => 
    [SMTPAuth] => 1 
    [Username] => blah 
    [Password] => blah 
    [Timeout] => 10 
    [SMTPDebug] => 
    [SMTPKeepAlive] => 
    [smtp] => 
    [to] => Array ( 
        [0] => Array ( 
            [0] => blah@blah.com 
            [1] => blah 
        ) 
    ) 
    [cc] => Array ( ) 
    [bcc] => Array ( ) 
    [ReplyTo] => Array ( ) 
    [attachment] => Array ( ) 
    [CustomHeader] => Array ( ) 
    [message_type] => 
    [boundary] => Array ( ) 
    [language] => Array ( ) 
    [error_count] => 0 
    [LE] => 
)
4

3 回答 3

0

我相信您缺少实际的发送部分: $mailer->Send(); 尝试添加并运行它

于 2012-06-18T14:22:16.927 回答
0

解决了,我试图对“发件人”和“发件人”使用不正确的值,我的服务器设置不正确。感谢吉姆和帕特里克的意见。

于 2012-06-20T13:01:19.057 回答
-1

名字 ".$_POST['fname']."company".$_POST['company']."Email".$_POST['email']."Telephone".$_POST['telelphone']."评论" .$_POST['comments']."";$headers="MIME-Version":1.0\r\n";$hearder="Content-type:text/html;charest=iso-8859-1\r \n";$headers.= "FROM:".$_POST['email']."\r\n";mail($to,$subject,$body,$headers);echo'

于 2013-07-20T17:58:52.450 回答