Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-19-2012, 08:07 PM   PM User | #1
akknobloch
New to the CF scene

 
Join Date: Jun 2012
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
akknobloch is an unknown quantity at this point
Warning: mail() SMTP server response: Need Rcpt command

I recently moved my website to a new host and I started getting this error when I would try to submit a form:
Warning: mail() [function.mail]: SMTP server response: 503 5.5.2 Need Rcpt command.
The email would send to the recipient, but the receipt would not send to the sender. Error said it was on line 51. I highlighted line 51 in red. Here is a part of the code:

$my_email = "clientchange@abgemail.com";
$continue = "/";
$sender = $_POST['emailedBy'];


// This line prevents values being entered in a URL

if ($Filed_By=="")
{
/* print("<script language=\"javascript\">window.history.back();</script>");*/
$noName=1;
}

if ($_SERVER['REQUEST_METHOD'] != "POST")
{
$noInfo=1;
exit;
}


// This line prevents a blank form being sent

if ($noName<>1)
{
while(list($key,$value) = each($_POST)){if(!(empty($value))){$set=1;}$message = $message . "$key: $value\n";} if($set!==1){header("location: $_SERVER[HTTP_REFERER]");exit;}

$message = stripslashes($message);
$message = "------------------------------" . "\n" .
"CLIENT CHANGE FORM SUBMISSION" . "\n" .
" ALLIANCE BENEFIT GROUP - IL " . "\n" .
"------------------------------" . "\n" .
$message . "\n" .
"------------------------------" . "\n";

$subject = "Client Change Form";
$headers = "From: " . "clientchange@abgemail.com" . "\n" . "Return-Path: " . "webmaster@abgemail.com" . "\n" . "Reply-To: " . "clientchange@abgemail.com" . "\n";

mail($my_email,$subject,$message,$headers);
mail($sender,$subject,$message,$headers);

$success=1;
}

?>

Last edited by akknobloch; 06-19-2012 at 08:56 PM..
akknobloch is offline   Reply With Quote
Old 06-20-2012, 12:16 AM   PM User | #2
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,902
Thanks: 5
Thanked 79 Times in 78 Posts
firepages will become famous soon enough
check that $sender = $_POST['emailedBy'] is actually getting set, the error itself means that you don't have a mail recipient ($sender) , check that is not empty.
__________________
resistance is...

MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
firepages is online now   Reply With Quote
Users who have thanked firepages for this post:
akknobloch (06-20-2012)
Old 06-20-2012, 01:55 PM   PM User | #3
akknobloch
New to the CF scene

 
Join Date: Jun 2012
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
akknobloch is an unknown quantity at this point
I feel like it is getting set. The user is inputing their email into a text box that has name = "emailedBy". How would I check further into this issue? Thanks for your help!
akknobloch is offline   Reply With Quote
Old 06-20-2012, 02:08 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Don't forget that headers should be separated by \r\n as well. Its possible that its misinterpreting the from header and considering everything as a part of the from.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
akknobloch (06-20-2012)
Old 06-20-2012, 02:12 PM   PM User | #5
akknobloch
New to the CF scene

 
Join Date: Jun 2012
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
akknobloch is an unknown quantity at this point
Fou-Lu - I have the headers seperated by \n. Is that fine or would it solve the issue by seperating them by using \r\n? I have never had an issue before just using \n.
akknobloch is offline   Reply With Quote
Old 06-20-2012, 02:15 PM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
I can't say it will solve the issue. But RFC specifies that headers are separated by \r\n, not by \n which separates content.
That's the very first thing I'd check. Mail() is somewhat tricky since it has quirks depending on the OS in use.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
akknobloch (06-20-2012)
Old 06-20-2012, 02:27 PM   PM User | #7
akknobloch
New to the CF scene

 
Join Date: Jun 2012
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
akknobloch is an unknown quantity at this point
Thanks. I tried seperating the $headers by \r\n, but the issue is still there. I am not sure why it is not able to pull the $sender email and then send the email. The first mail() option is working, but the second mail() option to the $sender is not.
akknobloch is offline   Reply With Quote
Old 06-20-2012, 02:46 PM   PM User | #8
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Is it not pulling the sender out of the post?
Check and see what the value of $sender is. If its a valid email, this is a host configuration that's blocking it.
Fou-Lu is offline   Reply With Quote
Old 06-20-2012, 05:29 PM   PM User | #9
akknobloch
New to the CF scene

 
Join Date: Jun 2012
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
akknobloch is an unknown quantity at this point
Sorry, but how would I find the value of the $sender? Use a debugger to step through the code? Thanks again.
akknobloch is offline   Reply With Quote
Old 06-20-2012, 05:34 PM   PM User | #10
Keleth
Senior Coder

 
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 Posts
Keleth is on a distinguished road
Just echo out the value...
Keleth is offline   Reply With Quote
Old 06-20-2012, 05:53 PM   PM User | #11
akknobloch
New to the CF scene

 
Join Date: Jun 2012
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
akknobloch is an unknown quantity at this point
I am currently testing the echo to see what result I get.

Last edited by akknobloch; 06-20-2012 at 06:00 PM..
akknobloch is offline   Reply With Quote
Old 06-20-2012, 06:13 PM   PM User | #12
akknobloch
New to the CF scene

 
Join Date: Jun 2012
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
akknobloch is an unknown quantity at this point
No luck. I tried to echo $sender, but when I submitted the form it did not output an email address. It just gave me the same error that I started with. What could my next step be? Thanks
akknobloch is offline   Reply With Quote
Old 06-20-2012, 06:17 PM   PM User | #13
Keleth
Senior Coder

 
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 Posts
Keleth is on a distinguished road
Do a print_r($_POST);.

If $sender doesn't have anything, that means your form is screwed up or something screwed up inbetween.
Keleth is offline   Reply With Quote
Old 06-20-2012, 06:37 PM   PM User | #14
akknobloch
New to the CF scene

 
Join Date: Jun 2012
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
akknobloch is an unknown quantity at this point
Here is my code. Let me know what you think. Also would it be useful to post the form as well?

PHP Code:
<?php

$my_email 
"clientchange@abgemail.com";
$continue "/";
$sender $_POST['Emailed_By'];


// This line prevents values being entered in a URL

if ($Filed_By=="")
{
 
/* print("<script language=\"javascript\">window.history.back();</script>");*/
 
$noName=1;
}

if (
$_SERVER['REQUEST_METHOD'] != "POST")
{
 
$noInfo=1;
 exit;
}


// This line prevents a blank form being sent

if ($noName<>1)
{
 while(list(
$key,$value) = each($_POST)){if(!(empty($value))){$set=1;}$message $message "$key: $value\n";} if($set!==1){header("location: $_SERVER[HTTP_REFERER]");exit;}

 
$message stripslashes($message);
 
$message "------------------------------" "\n" 
            
"CLIENT CHANGE  FORM SUBMISSION" "\n" .
            
" ALLIANCE BENEFIT GROUP OF IL " "\n" .
            
"------------------------------" "\n" .
            
$message "\n" 
            
"------------------------------" "\n";

 
$subject "Client Change Form";
 
$headers "From: " "clientchange@abgemail.com" "\r\n" "Return-Path: " "webmaster@abgemail.com" "\r\n" "Reply-To: " "clientchange@abgemail.com" "\r\n";

 
mail($my_email,$subject,$message,$headers);
 
mail($sender,$subject,$message,$headers);
 
 
$success=1;
}

require_once(
"header.php")

?>
akknobloch is offline   Reply With Quote
Old 06-20-2012, 06:39 PM   PM User | #15
Keleth
Senior Coder

 
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 Posts
Keleth is on a distinguished road
The problem is most likely on the form side. Like I said, print out the post variables, see if it matches what you think you should get. If not, then you know where your problem is.
Keleth is offline   Reply With Quote
Users who have thanked Keleth for this post:
akknobloch (06-20-2012)
Reply

Bookmarks

Tags
email, php, submit

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:38 AM.


Advertisement
Log in to turn off these ads.