2
votes

I am unable to send email from localhost using php script this is my code

<?php

ini_set("SMTP","[email protected]");

ini_set("smtp_port","25");

ini_set('sendmail_from', '[email protected]');

//define the receiver of the email
$to = '[email protected]';

//define the subject of the email
$subject = 'Test email'; 

//define the message to be sent. Each line should be separated with \n
$message = "Hello World!\n\nThis is my first mail."; 

//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: [email protected]\r\nReply-To: [email protected]";

//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 

echo $mail_sent ? "Mail sent" : "Mail failed";

?>

php.ini file...

[mail function]

; For Win32 only.

SMTP = localhost

smtp_port = 25

; For Win32 only.

sendmail_from [email protected]

the out put is "Mail failed"

please help me to solve my problem.

3
I doubt bhoi.test@gmail is a smtp serverPeeHaa

3 Answers

2
votes

I will tell you the easiest way.

You can use open-source Papercut and download the application and run it without any change in the xampp php.ini and sendmail.ini files. Then when you run your mail in php you will directly get it into papercut application.This is application is awesome and you don’t have to configure anything.

Note: Please don’t make any change in xampp like changing smtp_server.Just keep the default xampp settings .

1
votes

you need to install smtp server or set config for public mail servers

look this for example

SMTP = smtp.yourdomain.com
smtp_port = 25
username = [email protected]
password = yourmailpassord
sendmail_from = [email protected]
0
votes

I tried fake sendmail for windows and it worked for me. you can check it out here. http://glob.com.au/sendmail/ After than you have to set sendmail_path in php.ini to the path of the sendmail path on your hard drive.