3

I found a php-script on internet:

<?php
$to = "*******@yahoo.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "****@*****.nu";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

and it work perfectly if I use it from my web-hotel. But i need it to by run on my home-server and I just simply not receiving anything. I tried to run it with php -f phpTest, and through both local ip (10.0.0.2) and by using a global hostname. I just get "Mail send" without getting the mail.

It is a ubuntu-server I am running at and it uses apache2. Like I said, it is no wrong in script because it worked on web-hotel. It should be something with my local settings, but I can't figure out what.

All help would be appreciated!

\\demon

3
  • 3
    do you have a mail dæmon set up? If not, best to ask about that on superuser. Commented Oct 13, 2013 at 10:18
  • You should check your mail logs/settings on your server. Commented Oct 13, 2013 at 10:44
  • Check your destination spam folder? Do you sign your messages? Commented Oct 13, 2013 at 11:09

2 Answers 2

1

The PHP mail function uses a local MTA (Mail Transport Agent), that is a mail deamon running on the same machine as your PHP interpreter and your Apache web server.

So you must install and configure one on your Ubuntu setup. sendmail is the classic one, but exim is said to be easily configurable, and can use your current SMTP server as a smarthost relay, which works well for a home server.

sudo apt-get install exim4-daemon-light
sudo dpkg-reconfigure exim4-config
Sign up to request clarification or add additional context in comments.

Comments

1

Instead of relying on the builtin mail function which needs a working MTA, you could use a library like Swiftmailer to send the mail through an existing SMTP server (e.g. your regular mail address). That way you have the additional bonus of less spam filtering (because spam filters are sometimes very suspicious of mails that were sent from home servers).

1 Comment

This is absolutely the best Option for you. I once tried to set up my own Mail SMTP Server at Home but with a dynamic IP you could totally forget it. Even with a fixed IP you still get filtered out by most Mail Servers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.