Forum Moderators: coopster

Message Too Old, No Replies

PHP built in mail function

testing on localhost

         

naiquevin

3:13 pm on May 4, 2009 (gmt 0)

10+ Year Member



I am using XAMPP to test PHP code offline ..

When I tried if mail can be sent it showed me this 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 D:\xampp\htdocs\project\m_pro_edit.php on line 174

Can this be done offline by modifying some settings ? or is it possible only after hosting it on a server ?

Thank you

eeek

2:13 am on May 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Did you look at the settings in php.ini?
Do you have a sever listening on port 25?

naiquevin

5:02 am on May 5, 2009 (gmt 0)

10+ Year Member



Yes I checked in php.ini file ...
This is what I found


[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
;sendmail_from = me@example.com

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path = "D:\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 =

But I dont know what to make of it.. I tried removing the first semi colon .. but it doesnt seem to work
I am quite new to PHP

An156

6:35 am on May 5, 2009 (gmt 0)

10+ Year Member



write this before the mail function

ini_set ("sendmail_from","yourname@domai.com");

naiquevin

12:42 pm on May 5, 2009 (gmt 0)

10+ Year Member



Hi thanks for the reply ..

I am calling the mail() function this way

mail($to, $subject, $msg, 'From:' . $from);

where $from is already set as "myname@domain.com"

BTW I dont havent registered a domain yet... this I am doing over XAMPP. Still using myname@domain.com which is fake!

Can you please shed some more light on how this works? I mean suppose I define a fake id .. then will it still send the mail..
conversely, if I set the value to some other persons email id, then does it mean i can send mail using his id without his knowledge..
Sorry if these questions are dumb!

idfer

4:05 pm on May 5, 2009 (gmt 0)

10+ Year Member



Yes, when you send email, you can set the "From" address to be anyone. It's a weakness in the email protocol, and one reason for so much spam. However, many email servers will filter out your messages if they suspect that the From address is being forged.

As far as your error... XAMPP on Windows uses SMTP which is the same mechanism that your email client uses to send email. So what you need to do is set

SMTP = same host that you use in your email client

This can be either your ISP's SMTP server or your web host's SMTP server, just copy the settings that you use in your usual email client.

hartstsc

5:06 pm on May 10, 2009 (gmt 0)

10+ Year Member



I had the same type of problem using Wampserver under Windows.
I had to write an E-mail script as a solution to a case in my PHP-course.
On [php.net...] I found a temporary solution. I will not copy it here. Check it out yourself.
You need to fake the email sending. See [glob.com.au...]
This doesn't really solve the problem, but at least you can test your script without the crash.

I also asked my coach why it wasn't working. His explanation was, that Wampserver - and perhaps XXAMP is the same - hasn't a mailserver running under localhost.
When it would be uploaded to my webhost it would work (hasn't checked that yet).

penders

5:51 pm on May 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I also asked my coach why it wasn't working. His explanation was, that Wampserver - and perhaps XXAMP is the same - hasn't a mailserver running under localhost.

Yes, but XAMPP does come with Mercury Mail which can be enabled for this purpose - I assume.

But to enable mail() to be able to send email you don't necessarily need Mercury Mail. As idfer suggests above, just edit the SMTP, smtp_port and sendmail_from settings in php.ini. After editing php.ini you need to restart Apache. You might also need to edit your firewall settings. This should work OK under a test environment on Windows.