Send email from localhost to Gmail
I am new to PHP and want us to send email from localhost to my gmail address.
I am using ubuntu 9.10 and have already installed libphp-phpmailer from Synaptic Package Manager option.
I used:
$to = "abc@gmail.com";
$subject = "Account Confirmation";
$headers = "From: xyz@gmail.com";
$message = "Testing";
$mail = mail($to, $subject, $message, $headers);
if ($mail) {
echo "Mail sent.";
} else {
echo "Some Error occur.";
}
And it shows that an error has occurred.
a source to share
You don't need PHPMailer (thus a package libphp-phpmailer
) to use the function mail()
(also I would recommend swiftmailer via PHPMailer at any time). Also, if you want to use the feature mail()
, you need a Mail Transfer Agent ( MTA ). I recommend installing the package postfix
(it's available by default in Ubuntu, just use sudo apt-get install postfix
). After that, your code should output Mail sent.
:)
-1 to the other two answers for not reading your question.
a source to share