i wanted to do a feedback or contact us page where user can give feedback and automatically will be sent to a specific admin (example@gmail.com).. i encounter this error..i dont know what to do..

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:\xampp\htdocs\test....php on line 7
We encountered an error sending your mail..

what do i do?? please help..tq

First check if your SMTP server is running and is correctly set up.

i think its running..what about, what it says..

"verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()".
do i need to verify anthing or change php.ini

mail() function is trying to connect to localhost at port 25 (which are default values). You make sure that php.ini settings are the same. This is how my php.ini is set:

SMTP = localhost
smtp_port = 25

But I am on Linux and am not sure how it works on Windows. Please also check the form of To: adresses. Thi is the note form PHP mail manual:

The Windows implementation of mail() differs in many ways from the Unix implementation. First, it doesn't use a local binary for composing messages but only operates on direct sockets which means a MTA is needed listening on a network socket (which can either on the localhost or a remote machine).

Second, the custom headers like From:, Cc:, Bcc: and Date: are not interpreted by the MTA in the first place, but are parsed by PHP.

As such, the to parameter should not be an address in the form of "Something <someone@example.com>". The mail command may not parse this properly while talking with the MTA.

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = postmaster@localhost

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
;sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =

; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = Off

; Log all mail() calls including the full path of the script, line #, to address and headers
;mail.log = "C:\xampp\php\logs\php_mail.log"

<+> This is what my php.ini looks like..i dont think it has any problem..

@Broj1 :

I change the codes a bit...
it still have errors but..a different one..

" Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING "

got any ideas??

sorry..that was my mistake..
here's a new one..

Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing

Add From header with your (or some) email address. This is an example from PHP.net:

$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

You can also set it in php.ini:

sendmail_from = me@example.com

@broj1 :

the email has been suceesfully sent..but..there is no email sent..what now..

Sorry, I am not sure if I understood this. Did you mean you did not receive the mail that was successfully sent?

One thing: enable logging in php.ini. Uncomment the following line:

mail.log = "C:\xampp\php\logs\php_mail.log"

Now you can check in the log what happened. And make sure you set and use valid addresses.

" Your mail was sent successfully "

but..i did not received the email..

See my last post.

i did uncomment the php.ini..that line you said..but still, i did not receive any data..

i mean i still havent received any emails..

Have you checked the log file?

Is the website hosted online?? If not; you will have to upload it before the mail can be sent.
You will need to download PHPMailer and once successfully done, then u can use this code;

<?php
require("class.phpmailer.php");
    $email = $_POST['email'];
    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->Host = "localhost";
    $mail->From = "source_email@domain.com";
    $mail->FromName  =  "Your_name";
    $mail->AddAddress("recipient_1@domain.com");
    //$mail->AddAddress("recipient_2@domain.com");
    $msg = "This is the sample message";
    $subject = "My first Email";
    $mail->SMTPAuth = "true";
    $mail->Username = "your_gmail_account@gmail.com";
    $mail->Password =  "your_gmail_password";
    $mail->Port  =  "25";
    $mail->Subject = $subject;
    $mail->Body = $msg;
    $mail->WordWrap = 50;
    if(!$mail->Send())
    {
        echo 'Message was not sent.';
        echo 'Mailer error: ' . $mail->ErrorInfo;
    }
    else
    {
        echo 'Mail has been sent.';
    }
?>

Hope that helps

Have you checked the log file?

what log file??

php_mail.log

that's what you need. and make sure your SMTP port of the e-mail website has that port number

This is what it says in your php.ini:

mail.log = "C:\xampp\php\logs\php_mail.log"

(this line has to be uncommented)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.