Solved

an error message that i cannot understand

Posted on 2006-11-12
16
338 Views
Last Modified: 2010-08-05
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

0
Comment
Question by:derrida
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
  • +2
16 Comments
 
LVL 8

Expert Comment

by:Rytmis
ID: 17924622
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
 
LVL 1

Author Comment

by:derrida
ID: 17924631
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
 
LVL 8

Expert Comment

by:Rytmis
ID: 17924662
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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 1

Author Comment

by:derrida
ID: 17924706
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
 
LVL 8

Expert Comment

by:Rytmis
ID: 17924721
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
 
LVL 1

Author Comment

by:derrida
ID: 17924733
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
 
LVL 8

Expert Comment

by:Rytmis
ID: 17924739
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
 
LVL 1

Author Comment

by:derrida
ID: 17924748
hi

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

ron
0
 

Expert Comment

by:Jezdo
ID: 17924943
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
 
LVL 43

Expert Comment

by:ravenpl
ID: 17926171
> 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
 
LVL 1

Author Comment

by:derrida
ID: 17928318
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
 
LVL 8

Expert Comment

by:Rytmis
ID: 17928352
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
 
LVL 1

Author Comment

by:derrida
ID: 17928393
hi

i still get the same error message.


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


ron
0
 
LVL 18

Expert Comment

by:Mark Gilbert
ID: 17928922
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
 

Accepted Solution

by:
Jezdo earned 125 total points
ID: 17937306
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
 
LVL 43

Expert Comment

by:ravenpl
ID: 18120720
And what was wrong?
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question