Question:
using mail function in php ?
person x
2008-02-04 04:22:12 UTC
hi....i try to make the email form with mail function like this :

$to = "localhost";
$subject = "Contact Us";
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ;
?>

but i get this :
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:\wamp\www\mail.php on line 7

i verified the 'SMTP' and "smtp_port" in the php.ini..so whats the problem ..iam using wamp with php 5.2.5.

can i set the variable $to above like :

$to = "anyname@yahoo.com" for example

or $to = "name@localhost"

thanks
Six answers:
Shell Answer Man
2008-02-04 07:16:40 UTC
"localhost" is a pointer to your own computer. that means that in order to keep using "localhost", you must have a mail server running on your own computer. Not worth the trouble.



You should change "localhost" to the SMTP host provided to you by your ISP. It may be something like 'smtp.providername.net'. Consult with your ISP for help.



Leave the port number alone.





Just for reference, ANY TIME you move your php program to a computer on a different ISP, you will have to consider that you usually can't use one ISP's SMTP server from a computer connected to another ISP's network - they usually block other ISPs' SMTP to reduce spam issues.



Secondly, don't overdo it with outgoing messages from your PHP program. Testing, yes. But you might send a red flag to your ISP if you're sending too many e-mails. They might disable e-mail services or limit how many you can send out over a certain time, so if it works at first and goes wacky, this is why.



L8rz.
Bizzi
2008-02-04 04:38:16 UTC
Depending on if you are hosting the form yourself or if it's on a remote server.

If it's on a remote server the SMTP is not accessable. Contact your webhost for more info.

If it's hosted on your own system then you may not have SMTP installed. Or if you try to use the SMTP from your internet provider they 9 out of 10 times do not allow others to use their SMTP. Windows XP does not support SMTP by default Windows 2000 does for some reason.
?
2016-05-24 11:31:25 UTC
you can't use the mail() function on your localhost, unless you setup your mail boxes. It's a pain, just upload it to a web server that has PHP installed, and it will work. Test you logic before hand, eg. echo("this is my mail being set to $to $title
psy80uk
2008-02-04 04:32:11 UTC
"Failed to connect to mailserver at "localhost" port 25"



Your mail server is not running.
2008-02-04 06:19:45 UTC
upload your script to real server (web host).

email script need SMTP server to send email.
Lady Sardonyx
2008-02-04 04:30:23 UTC
I think that will work because it won't recognize an email address until you tell it what to recognize. but, of course my php is rusty I could be wrong.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...