Php code or stmp problem?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

mbluezor
Forum Newbie
Posts: 8
Joined: Wed May 19, 2010 5:03 am

Php code or stmp problem?

Post 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!
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: Php code or stmp problem?

Post 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");
mbluezor
Forum Newbie
Posts: 8
Joined: Wed May 19, 2010 5:03 am

Re: Php code or stmp problem?

Post 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 :(
mbluezor
Forum Newbie
Posts: 8
Joined: Wed May 19, 2010 5:03 am

Re: Php code or stmp problem?

Post 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?
roders
Forum Commoner
Posts: 68
Joined: Tue Oct 20, 2009 9:29 am

Re: Php code or stmp problem?

Post by roders »

If you've bought the hosting then you need to find out if they allow email relay, they might have disable it.
User avatar
zeus1
Forum Newbie
Posts: 22
Joined: Tue May 18, 2010 10:45 pm
Location: /Under/The/AppleTree.png

Re: Php code or stmp problem?

Post 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.
User avatar
zeus1
Forum Newbie
Posts: 22
Joined: Tue May 18, 2010 10:45 pm
Location: /Under/The/AppleTree.png

Re: Php code or stmp problem?

Post 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
mbluezor
Forum Newbie
Posts: 8
Joined: Wed May 19, 2010 5:03 am

Re: Php code or stmp problem?

Post 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
User avatar
zeus1
Forum Newbie
Posts: 22
Joined: Tue May 18, 2010 10:45 pm
Location: /Under/The/AppleTree.png

Re: Php code or stmp problem?

Post by zeus1 »

Well, it says you are running the SMTP server locally. Do you have an smtp server running?
Last edited by zeus1 on Wed May 19, 2010 2:53 pm, edited 1 time in total.
mbluezor
Forum Newbie
Posts: 8
Joined: Wed May 19, 2010 5:03 am

Re: Php code or stmp problem?

Post by mbluezor »

by locally you mean on my PC?

no
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Php code or stmp problem?

Post by John Cartwright »

mbluezor wrote:by locally you mean on my PC?

no
Locally as in where you are running this script on.
User avatar
zeus1
Forum Newbie
Posts: 22
Joined: Tue May 18, 2010 10:45 pm
Location: /Under/The/AppleTree.png

Re: Php code or stmp problem?

Post 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!
mbluezor
Forum Newbie
Posts: 8
Joined: Wed May 19, 2010 5:03 am

Re: Php code or stmp problem?

Post by mbluezor »

Thank you, i will try this
mbluezor
Forum Newbie
Posts: 8
Joined: Wed May 19, 2010 5:03 am

Re: Php code or stmp problem?

Post 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: .
mbluezor
Forum Newbie
Posts: 8
Joined: Wed May 19, 2010 5:03 am

Re: Php code or stmp problem?

Post 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
Post Reply