tags:

views:

1216

answers:

4

Hello, 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, Mike.

+4  A: 

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('[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.

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.

André Hoffmann
Please note that many hosters block this (using smtp server outside your domain) to avoid spammers... :)
Toto
+1  A: 

The script wouldn't necessarily show errors, on failure $mail would be false.

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

David Archer
A: 

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.).

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)....

Toto
A: 

If possible, check to see that your server is resolving seznam.cz to 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.

You probably don't have this problem, but it wouldn't hurt to check.

Colin O'Dell