im testing a sendmail function in PHP.
The first, i used mail() function, this is my code:
<?php
$to="meo.spt@gmail.com";
$subject="This is test mail";
$message="Hello, this is test mail from Viet May Cor. \n Best regards!";
$from="meo_spt@yahoo.com";
$headers="From: $from";
mail($to,$subject,$message,$headers);
?>
and i got an error: "Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\AppServ\www\mail.php on line 7"
The second, i was try using PHPmailer, i got an error too,
<?php
include("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "meo.spt@gmail.com"; // GMAIL username
$mail->Password = "gmailpass"; // GMAIL password
$mail->From = "meo.spt@gmail.com";
$mail->Subject = "PHPMailer Test Subject via gmail";
$mail->Body = "Hi, this is a test";
$mail->AddAddress("meo.spt@gmail.com", "Hussain");
$mail->send();
?>
This is result: SMTP Error: Could not connect to SMTP host.
Final, i tested the most basic mail function in phpmailer;
<?php
require_once('../class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$mail->IsSendmail(); // telling the class to use SendMail transport
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->AddReplyTo("meo.spt@gmail.com","First Last");
$mail->SetFrom('meo.spt@gmail.com', 'First Last');
$mail->AddReplyTo("meo.spt@gmail.com","First Last");
$address = "meo.spt@gmail.com";
$mail->AddAddress($address, "John Doe");
$mail->Subject = "PHPMailer Test Subject via Sendmail, basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
and there all was i got: "Could not instantiate mail function. Mailer Error: Could not instantiate mail function. "
I'm using Appache 2.2, and i haven't config anything yet. I thought that sending mail in PHP was too easy before, but i was wrong. There is need to install, config anything ? Please anyone tell my a solution ? Thanks to all