简体   繁体   中英

Not able to send mail by php-script

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM