我无法通过localhost使用php发送邮件[复制]

This question already has an answer here:

I am using ubuntu with xampp. I need to send mail from localhost . I am new to php.Can u help me what are all i need to configure to send mail from localhost?

<?php
$to = "mymail@gmail.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "othemail@gmail.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers) or die("unable to send");
echo "Mail Sent.";
?> 
</div>

You should send email using SMTP, it will work.
It will work in win32. i am not sure about any other.
Check following link.

Send email from localhost running XAMMP in PHP using GMAIL mail server

you should try this link to send mail from localhost http://www.mittalpatel.co.in/php_send_mail_from_localhost_using_gmail_smtp

which gives you insight about how to send mail from localhost using third party SMTP server.