PHP - mail() 函数在我的主机上不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1322434/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP - mail() function not working on my hosting
提问by Mike
I have a simple script that works fine on any of my other servers, but on that one I need, it doesn't.
我有一个简单的脚本,可以在我的任何其他服务器上正常工作,但在我需要的那台服务器上,它没有。
<?php
$mail = mail('[email protected]', 'My Subject', 'msg');
?>
I tryed calling the webhost provider, but can't reach them. Also tryed to google some advice, but nobody seems to have the same problem.
我尝试致电虚拟主机提供商,但无法联系到他们。也尝试谷歌一些建议,但似乎没有人有同样的问题。
The script doesn't show any error msg, it just doesn? do anything.
脚本没有显示任何错误消息,它只是没有?做任何事情。
Do you know what the problem is, or any other way around to send email?
您知道问题出在哪里吗,或者知道其他发送电子邮件的方式吗?
Thanks
谢谢
回答by André Hoffmann
Seems like sendmail is not configured on your server.
您的服务器上似乎没有配置 sendmail。
What you can do though is to create a mail account on f.e. gmail,yahoo mail or similar and use Zend_Mailto send mails from this account using SMTP.
您可以做的是在 fe gmail、yahoo 邮件或类似邮件上创建一个邮件帐户,然后使用Zend_Mail使用 SMTP 从该帐户发送邮件。
I took this code example from the Zend Framework documentation:
我从 Zend Framework 文档中获取了这个代码示例:
$config = array('auth' => 'login',
'username' => 'myusername',
'password' => 'password');
$transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
$mail = new Zend_Mail();
$mail->setBodyText('This is the text of the mail.');
$mail->setFrom('[email protected]', 'Some Sender');
$mail->addTo('[email protected]', 'Some Recipient');
$mail->setSubject('TestSubject');
$mail->send($transport);
This doesn't require sendmail to be configured as you are using a preexistent mail server that allows smtp.
这不需要配置 sendmail,因为您使用的是允许 smtp 的预先存在的邮件服务器。
UPDATE:As toto pointed out it can be possible that SMTP is also blocked by your hoster. In this case you can try to use SSL by simply adding two entries to the Zend_Mail config which then should look like this:
更新:Toto 指出 SMTP 也可能被您的主机阻止。在这种情况下,您可以通过简单地向 Zend_Mail 配置添加两个条目来尝试使用 SSL,然后应该如下所示:
$config = array('auth' => 'login',
'username' => 'myusername',
'password' => 'password',
'ssl' => 'ssl',
'port' => 465);
Hope this helps.
希望这可以帮助。
回答by Dave Archer
The script wouldn't necessarily show errors, on failure $mail would be false.
脚本不一定会显示错误,失败时 $mail 将是错误的。
Some possibilities
一些可能性
Your host might have blocked those ports.
If its a windows host you might not have set up your mail settings in php.ini
Take a look at the php mail manual page. In the examples, it shows you can add extra headers. The mail server that your host connects to might require certain basic headers
您的主机可能阻止了这些端口。
如果它是 Windows 主机,您可能没有在 php.ini 中设置邮件设置
查看php 邮件手册页。在示例中,它显示您可以添加额外的标题。您的主机连接到的邮件服务器可能需要某些基本标头
回答by Toto
Only this hosting company can answer. We can only make assumptions.
只有这家托管公司可以回答。我们只能做出假设。
But simply said: if this code works with other hosting companies and not this one. It is certainly a config issue (php.ini, smtp gateway/server, local firewall, etc.).
但简单地说:如果此代码适用于其他托管公司而不是这家公司。这当然是一个配置问题(php.ini、smtp 网关/服务器、本地防火墙等)。
Cheap hosting companies have usually a very good support service. ;) So keep trying to reach them or quite them (Imagine the day you have a big issue)....
廉价的托管公司通常有很好的支持服务。;) 因此,请继续尝试联系他们或与他们联系(想象一下您遇到大问题的那一天)......
回答by Colin O'Dell
If possible, check to see that your server is resolving seznam.czto the proper IP address. I had a similar issue once where my server's DNS thought it hosted a certain domain, so all emails to that domain never left the box! Took us a while to figure that one out.
如果可能,请检查您的服务器是否将seznam.cz解析为正确的 IP 地址。我曾经遇到过类似的问题,我的服务器的 DNS 认为它托管了某个域,因此所有发送到该域的电子邮件都没有离开过盒子!我们花了一段时间才弄明白。
You probably don't have this problem, but it wouldn't hurt to check.
您可能没有这个问题,但检查一下也无妨。

