im testing a sendmail function in PHP.
The first, i used mail() function, this is my code:

$subject="This is test mail";
$message="Hello, this is test mail from Viet May Cor. \n Best regards!";
$headers="From: $from";

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,

$mail             = new PHPMailer();
$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");


This is result: SMTP Error: Could not connect to SMTP host.

Final, i tested the most basic mail function in phpmailer;

$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->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

Edited by meo_spt: n/a

7 Years
Discussion Span
Last Post by meo_spt

Thanks for all, My code works ok now, because there wasn't smtp server installed before.

But for the code send mail via smtp gmail, i changed port and prefix as

Perhaps this: http://phpmailer.worxware.com/index.php?pg=tip_gmail

But still getting error here:

Warning: stream_socket_enable_crypto() [streams.crypto]: this stream does not support SSL/crypto in C:\AppServ\www\test\mail\class.smtp.php on line 197

This is content at line 197:

if(!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
return false;

Anybody tell me a solution ?


Heyah, that was successful, cause in Apache version was used(2.5.8), after i run 2.5.10 version, that all successful!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.