Link to home
Start Free TrialLog in
Avatar of derrida
derrida

asked on

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

Avatar of Rytmis
Rytmis

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.
Avatar of derrida

ASKER

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
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?
Avatar of derrida

ASKER

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
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.
Avatar of derrida

ASKER

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
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?
Avatar of derrida

ASKER

hi

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

ron
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).
> 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.
Avatar of derrida

ASKER

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
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.
Avatar of derrida

ASKER

hi

i still get the same error message.


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


ron
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
ASKER CERTIFIED SOLUTION
Avatar of Jezdo
Jezdo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And what was wrong?