Page 1 of 2

Php code or stmp problem?

Posted: Wed May 19, 2010 5:11 am
by mbluezor
I'm new to this so please excuse the noobness :lol:

I have a small website with a feedback form hosted on a payed host server.
This is my simple php code:(i have a more complex one but it didn't work so i simplified the code to this and it still doesn't work so I'm thinking maybe its some sort of STMP problem or php.ini? <--- 8O

Code: Select all

$to = "someone@somewhere.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "info@somewhere.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
I get this error whenever i submit the form:

Warning: mail() [function.mail]: SMTP server response: 501 Your domain does not seem to be valid. Could not find MX record for your domain. in C:\Inetpub\vhosts\********\httpdocs\contact.php on line 70
Mail Sent.


I would appreciate any answers.
Thank you!

Re: Php code or stmp problem?

Posted: Wed May 19, 2010 5:19 am
by Apollo
You didn't use the additional -f parameter, meaning mail() will actually use a generic address from your server as the From address. And since your script appearsto be somewhere on C:\ you're using your own localhost, which is probably not a MX-registered mailserver.

Try this instead: (mind the -f thingy at the end)

Code: Select all

mail($to,$subject,$message,$headers,"-f$from");

Re: Php code or stmp problem?

Posted: Wed May 19, 2010 5:25 am
by mbluezor
Apollo wrote:You didn't use the additional -f parameter, meaning mail() will actually use a generic address from your server as the From address. And since your script appearsto be somewhere on C:\ you're using your own localhost, which is probably not a MX-registered mailserver.

Try this instead: (mind the -f thingy at the end)

Code: Select all

mail($to,$subject,$message,$headers,"-f$from");
Same error :(

Re: Php code or stmp problem?

Posted: Wed May 19, 2010 5:51 am
by mbluezor
Is there something you usually have to configure on a webhost server the first time to be able to use the mail(); function?

Re: Php code or stmp problem?

Posted: Wed May 19, 2010 7:15 am
by roders
If you've bought the hosting then you need to find out if they allow email relay, they might have disable it.

Re: Php code or stmp problem?

Posted: Wed May 19, 2010 1:11 pm
by zeus1
Are you sure there is an SMTP server set up on the server? If not, you have to use your own SMTP server. These setting are configured in the php.ini file. Check out the options at http://www.w3schools.com/PHP/php_ref_mail.asp. To figure out your settings create a script with only the lines

Code: Select all

 <? phpinfo(); ?>
If these are wrong, you will have to edit or create your own php.ini file with the settings you prefer. A lot of hosting companies allow this. If you are hosting it yourself, you probably don't have an SMTP server configured. You are probably better off using your own, like gmail or yahoo, and setting it up in the php.ini file, rather than setting up an smtp server which also requires a functioning DNS and appropriate reverse lookups if you don't want to be counted as spam.

Re: Php code or stmp problem?

Posted: Wed May 19, 2010 1:41 pm
by zeus1
Actually, if you intend to use gmail, yahoo, etc, you will need a PEAR extension to use remote SMTP servers and SMTP authentication. Check out this link for more details: http://email.about.com/od/emailprogramm ... cation.htm

Re: Php code or stmp problem?

Posted: Wed May 19, 2010 2:50 pm
by mbluezor
Thanks Zeus,
The php.ini file says:


SMTP localhost localhost
smtp_port 25 25

What does this mean, and how do i make it work ?
Thank you

Re: Php code or stmp problem?

Posted: Wed May 19, 2010 2:51 pm
by zeus1
Well, it says you are running the SMTP server locally. Do you have an smtp server running?

Re: Php code or stmp problem?

Posted: Wed May 19, 2010 2:52 pm
by mbluezor
by locally you mean on my PC?

no

Re: Php code or stmp problem?

Posted: Wed May 19, 2010 2:54 pm
by John Cartwright
mbluezor wrote:by locally you mean on my PC?

no
Locally as in where you are running this script on.

Re: Php code or stmp problem?

Posted: Wed May 19, 2010 2:57 pm
by zeus1
Yea, thats the problem. PHP mail() function uses an smtp server to send mail. PHP does not emulate an SMTP, it needs one. My suggestion to you is to use your gmail's or another service provider's smtp. Check out http://email.about.com/od/emailprogramm ... cation.htm. You will need this info for gmail
smtp.gmail.com (use authentication)
Use Authentication: Yes
Port for TLS/STARTTLS: 587
Port for SSL: 465
I got it from: http://mail.google.com/s ... swer=13287 Follow the guide on how to send smtp using authentication. Let me know if you run into problems. Good luck!

Re: Php code or stmp problem?

Posted: Wed May 19, 2010 3:02 pm
by mbluezor
Thank you, i will try this

Re: Php code or stmp problem?

Posted: Wed May 19, 2010 3:08 pm
by mbluezor
Btw, judging by the error:
501 Your domain does not seem to be valid, Could not find MX record for your domain.

Error Description: This error means that the sending email address contains a domain that is not a registered domain name.

Error Resolution: This check is done when the following feature is enabled. The sender should check their email client settings and ensure that their configured email sender address contains a correct and valid domain name after the @ sign.

and

sendmail_from postmaster@win17.globehosting.com

"win17.globehosting.com" is not my domain, do you think this could be the problem?
Also, is it common for webhosts not to have a working STMP server?After all it's just a small feedback form on the contact page...I can't imagine everyone running trough all this trouble just to be able to use the mail(); function ? :cry: .

Re: Php code or stmp problem?

Posted: Thu May 20, 2010 5:54 am
by mbluezor
New problem, I cannot find a php.ini file on my host.It seems there is one in C:windows or somewhere on the server but i don't have acces to it.
Should i create one?But how and where?
My files look like this?

anon_ftp
cgi-bin
error_docs
httpdocs
httpsdocs
private
statistics
subdomains
vault_scripts
web_users
Security