PHP mail()不起作用

问题描述:

我想使用激活邮件等脚本编写一个简单的注册表单。但是由于某些原因mail()不发送电子邮件,或者我的3个不同的电子邮件帐户(hotmail,gmail,yahoo)没有收到他们,因此甚至不将它们放在垃圾邮件文件夹中。

I want to script a simple registration form with activation mail and so on. But for some reason mail() doesn't send the emails, or my 3 different email accounts (hotmail,gmail,yahoo) don't receive them and therefore don't even put them in the spam folder.

代码:

<?php
    $mailto = 'xxx@example.com';
    $subject = 'the subject';
    $message = 'the message';
    $from = 'system@example.net';
    $header = 'From:'.$from;

    if(mail($mailto,$subject,$message,$header)) {
        echo 'Email on the way';
    }
?>

每当它输出电子邮件的时候,所以mail()返回true,对吧?我真的没有得到它,我甚至试图关闭我的小骗子(虽然我没有阻止SMTP)。

Everytime it outputs 'Email on the way' so mail() returns true, right? I really don't get it, I've even tried to turn off my little snitch (although I didn't block SMTP).

请参阅 Jeff Atwood的这篇文章

简而言之:只是因为你的代码将电子邮件交给邮件传输代理,意味着它会交付。是的, mail()返回true意味着接受交付 - 这意味着看起来像一个电子邮件,我会尝试提供这个,而不是交付。即使 mail()的说明书

In short: Just because your code has handed the e-mail to a Mail Transfer Agent, it doesn't mean it will be delivered. Yes, mail() returning true means "accepted for delivery" - which means "Looks like an e-mail, I'll try to deliver this", not "It is delivered". Even the manual for mail() says:


重要的是要注意,只是因为邮件被接受送达,所以它不意味着邮件将实际到达目的地。

It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.

Soooo:检查您的MTA(是从您当地的电子邮件计算机?),尝试发送到本地地址(如果地址是本地的,是否已经交付?),尝试使用与PHP脚本相同的设置从邮件客户端发送电子邮件,尝试发送到一个较小的邮件主机,允许您关闭反垃圾邮件(是否在网络外部传送?)。另外,请阅读该文章,并检查那里提到的要点。

Soooo: check your MTA (is the e-mail sent from your local computer?), try to send to a local address (if the address is local, does it get delivered?), try to send an e-mail from your mail client, using the same settings as your PHP script, try to send to a smaller mail-hoster which allows you tu switch off antispam (is it delivered outside your network?). Also, read that article, and check the points mentioned there.