an error message that i cannot understand

hi
i am new in php and i`m trying to build a small shpping cart with a tutorial.
everything works until i try to send it i get this error messahe:
Warning: mail() [function.mail]: SMTP server response: 501 5.5.2 Syntax: RCPT TO: <address> in ...

what is wrong here and how to fix it?

and maybe a more broad question: if i get an error message that i cannot figure out where can i check for it? i tryed in google but did not get anything i could understand.


best regards

ron

LVL 1
derridaAsked:
Who is Participating?
 
JezdoConnect With a Mentor Commented:
Comment all code before this and add next:
[code]
// This needs to be configured:
$to = "user@domain.com"; // Replace user & domain.com. Don't add anything.
// Make this your email!
// Don't change anything next
mail($to,"[ Test Email ]","If you see this MSG something is wrong with your previous code.") or die("SMTP server error: Mail not sent.");
[/code]
If you recive email, something is wrong with your code.
0
 
RytmisCommented:
Looks like your outbound mail server doesn't like the recipient address. If you could paste the bit where you call mail(), it'd make it easier to help.

Google is a great resource for finding information, but you need a bit of experience to first only search for the relevant part of the error message and then to recognize the relevant results.
0
 
derridaAuthor Commented:
hi

thanks for answring. this is the code:

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: <myemail@gmail.com>\r\n";
$headers .= "Cc: <myemail@gmail.com>\r\n";
$headers .= "X-Mailer: PHP / ".phpversion()."\r\n";

/* mail it */
mail($to, $subject, $message, $headers);

i sent the headers too cause i feel that there is where the problem is. the other elements are good i`m quite sure.

best regards

ron
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
RytmisCommented:
Actually, your headers look just fine. However, I'd like to see what $to contains -- is it possible that $to is empty or malformed, because that's what the SMTP server seems to be complaining about?
0
 
derridaAuthor Commented:
hi
it seem like you are right.

there is this code:
$to = "<" . $email .">";

but i cannot see where in the 3 setp checkout pages there is the definition of this variable.

according to the tutorial the email will go to the customer and to the administrator. how can i specify that, maybe to write just before that line something like:
$email="$_POST['email'], myemail$gmail.com";

as i said i`m new to php so it is possible that its a stupi move:)


ron
0
 
RytmisCommented:
Well, variables don't automatically persist across requests, so if you can't find a $email = something anywhere, that's definitely a problem.

One thing you could do is replace the mail() call with a die($to); so the script will terminate and print out the address instead of sending the email. That way you can check what the issue with the address is.
0
 
derridaAuthor Commented:
hi

i have commented the mail() and wrote die($to) but i still get this message:

Warning: mail() [function.mail]: SMTP server response: 501 5.5.2 Syntax: RCPT TO: <address> in C:\Program_files\wamp\www\shoppingCart\checkout3.php on line 252

can it be?

ron
0
 
RytmisCommented:
Well something funny is going on then. Most likely you commented out the wrong mail() or didn't actually update the file. See line 252 in C:\Program_files\wamp\www\shoppingCart\checkout3.php like the error message says: is there a mail() call there?
0
 
derridaAuthor Commented:
hi

no i have commented it. there is no mail() as far as i can see.

ron
0
 
JezdoCommented:
Is this on your local host?
Did you started up Mail server?
If I did saw very well, email (that to) must not be in format:
< email@domain.tld >
It shold be in:
email@domain.tld
I almost never use this function so I'm not expert on it.
And, I think your problem is in $to variable.
try to use $to = $email  or change $to var into $email (if you have $email var defined).
0
 
ravenplCommented:
> there is this code:
> $to = "<" . $email .">";
$to should not have the < > parens. It should contain pure email address only. The < > are added automatically by PHP. So in Your example smtp server gets
RCPT TO: <<some@where.com>>
which is wrong.
0
 
derridaAuthor Commented:
hi

thanks for the answer. well i did that and now i get this error message regarding the mail function:
mail($to, $subject, $message, $headers);

Warning: mail() [function.mail]: SMTP server response: 501 5.5.2 Syntax: RCPT TO: <address> in C:\Program_files\wamp\www\shoppingCart\checkout3.php on line 252


so it seem like nothing has changed.


ron
0
 
RytmisCommented:
Try forcing a known good email address in $to :

$to = "youremail@yourdomain.com";

just before the mail() call

That way you can verify that a good address will / won't work.
0
 
derridaAuthor Commented:
hi

i still get the same error message.


i do not have any idea why, all you said was so reasonable.


ron
0
 
Mark GilbertSenior Performance EngineerCommented:
I looked up the error 501 5.5.2 Syntax error and found the following:

Sender has no domain specified (usually in MAIL FROM)

Or:

SMTP session syntax invalid. (usually unbalanced brackets)

Source: http://www.icewarp.com/support/faq/3280.php

I would check the format of all email addresses being parsed before the mail() call.  One thing to note is that SPF records now generally get checked by servers.  If the email address you claim the email is being sent from doesn't actually match up when the SPF is checked, then you will also get similar messages.  You must ensure that if you are sending "from" a gmail address, that you correctly authenticate with their smtp server.  Have a look at PHPMailer classed which allow you to "log in" to smtp before sending mails...this will ensure your SPF records match: http://phpmailer.sourceforge.net
0
 
ravenplCommented:
And what was wrong?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.