PHP - mail()函数不能在我的主机上工作 [英] PHP - mail() function not working on my hosting

查看:99
本文介绍了PHP - mail()函数不能在我的主机上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的脚本,在任何我的其他服务器上都可以正常工作,但是在我需要的时候,它没有。

 <?php 
$ mail = mail('test@test.cz','我的主题' 'MSG');
?>

我尝试调用webhost提供商,但无法访问它们。还尝试google一些建议,但没有人似乎有同样的问题。



该脚本不显示任何错误msg,它只是做任何事情。



你知道问题是什么,还是其他方式发送电子邮件?



谢谢

解决方案

您的服务器上没有配置sendmail。



是创建一个邮件帐户fe gmail,yahoo邮件或类似邮件,并使用 Zend_Mail 从此发送邮件帐户使用SMTP。



我从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('这是邮件的文本');
$ mail-> setFrom(sender@test.com','Some Sender');
$ mail-> addTo(arecipient@test.com','Some Recipient');
$ mail-> setSubject('TestSubject');
$ mail-> send($ transport);

这不需要配置sendmail,因为您正在使用允许smtp的预留邮件服务器。



更新:
由于toto指出,您的主机也可能阻止SMTP。在这种情况下,您可以尝试使用SSL,只需向Zend_Mail配置中添加两个条目,然后应如下所示:

  $ config = array('auth'=>'login',
'username'=>'myusername',
'password'=>'password',
'ssl'= >'ssl',
'port'=> 465);

希望这有帮助。


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('test@test.cz', '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

解决方案

Seems like sendmail is not configured on your server.

What you can do though is to create a mail account on f.e. gmail,yahoo mail or similar and use Zend_Mail to send mails from this account using SMTP.

I took this code example from the Zend Framework documentation:

$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('sender@test.com', 'Some Sender');
$mail->addTo('recipient@test.com', '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.

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:

$config = array('auth' => 'login',
                'username' => 'myusername',
                'password' => 'password',
                'ssl' => 'ssl',
                'port' => 465);

Hope this helps.

这篇关于PHP - mail()函数不能在我的主机上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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