PHP feedback form issue

Associate
Joined
19 Dec 2005
Posts
641
Location
Perth, Western Australia
Hi i have a feedback page on my site but when i enter the details and try to send i get this error

Warning: mail() [function.mail]: SMTP server response: 501 <"test" <[email protected]>>: "@" or "." expected after ""test"" in D:\Domains\buildcompare.ie\wwwroot\Feedback.php on line 83

Warning: Cannot modify header information - headers already sent by (output started at D:\Domains\buildcompare.ie\wwwroot\Feedback.php:83) in D:\Domains\buildcompare.ie\wwwroot\Feedback.php on line 85

And this is the code for the php
PHP:
<?php
// ------------- CONFIGURABLE SECTION ------------------------
$mailto = '[email protected]' ;
$subject = "Feedback Form" ;
$formurl = "http://www.buildcompare.ie/feedback.html" ;
$errorurl = "http://www.buildcompare.ie/feedbackerror.html" ;
$thankyouurl = "http://www.buildcompare.ie/feedbackcomplete.html" ;
$email_is_required = 1;
$name_is_required = 1;
$comments_is_required = 1;
$uself = 0;
$use_envsender = 0;
$use_sendmailfrom = 0;
$use_webmaster_email_for_from = 0;
$use_utf8 = 1;
$my_recaptcha_private_key = '6Lc7xAcAAAAAAGUKQ8UYh5x2wI3j-7HOAf_r6YQN' ;
// -------------------- END OF CONFIGURABLE SECTION ---------------
$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$content_type = (!isset( $use_utf8 ) || ($use_utf8 == 0)) ? 'Content-Type: text/plain; charset="iso-8859-1"' : 'Content-Type: text/plain; charset="utf-8"' ;
if (!isset( $use_envsender )) { $use_envsender = 0 ; }
if (isset( $use_sendmailfrom ) && $use_sendmailfrom) {
ini_set( 'sendmail_from', $mailto );
}
$envsender = "-f$mailto" ;
$fullname = (isset($_POST['fullname']))? $_POST['fullname'] : $_POST['name'] ;
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$http_referrer = getenv( "HTTP_REFERER" );
if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
if (($email_is_required && (empty($email) || !preg_match('/@/', $email))) || ($name_is_required && empty($fullname)) || ($comments_is_required && empty($comments))) {
header( "Location: $errorurl" );
exit ;
}
if ( preg_match( "/[\r\n]/", $fullname ) || preg_match( "/[\r\n]/", $email ) ) {
header( "Location: $errorurl" );
exit ;
}
if (strlen( $my_recaptcha_private_key )) {
require_once( 'recaptchalib.php' );
$resp = recaptcha_check_answer ( $my_recaptcha_private_key, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field'] );
if (!$resp->is_valid) {
header( "Location: $errorurl" );
exit ;
}
}
if (empty($email)) {
$email = $mailto ;
}
$fromemail = (!isset( $use_webmaster_email_for_from ) || ($use_webmaster_email_for_from == 0)) ? $email : $mailto ;
if (function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc()) {
$comments = stripslashes( $comments );
}
$messageproper =
"This message was sent from:\n" .
"$http_referrer\n" .
"------------------------------------------------------------\n" .
"Name of sender: $fullname\n" .
"Email of sender: $email\n" .
"------------------------- COMMENTS -------------------------\n\n" .
$comments .
"\n\n------------------------------------------------------------\n" ;
$headers =
"From: \"$fullname\" <$fromemail>" . $headersep . "Reply-To: \"$fullname\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.15.0" .
$headersep . 'MIME-Version: 1.0' . $headersep . $content_type ;
if ($use_envsender) {
mail($mailto, $subject, $messageproper, $headers, $envsender );
}
else {
mail($mailto, $subject, $messageproper, $headers );
}
header( "Location: $thankyouurl" );
exit ;
?>
Does anyone know where i am going wrong?
 
Last edited:
I suspect the issue is with the headers, more specially the from address. Have you tried debugging the script by entering a plain email for the from address?

Also please edit your post and put code in the PHP tags with proper markup if possible.
 
Last edited:
I think the first error would be corrected by changing

Code:
"From: \"$fullname\" <$fromemail>" . $headersep . "Reply-To: \"$fullname\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.15.0" .

to

Code:
"From: $fullname <$fromemail>" . $headersep . "Reply-To: $fullname <$email>" . $headersep . "X-Mailer: chfeedback.php 2.15.0" .

Your second error is because you've outputted some data to the browser then tried to do a header redirect. Have you tried to output any information above this feedback.php code?
 
Hi pmwd i tried your code but i give exactly the same error.

And msm722 after you hit send feedback and it sends the email if goes to another page to show you its was sent.

I think the second error is there due to the first error, so if we can fix the first one the second error should go away
 
And msm722 after you hit send feedback and it sends the email if goes to another page to show you its was sent.

I'm not sure what you're saying here? What does the other page have to do with the error? My suggestion is to change the from header to "From: [email protected]" to see if this overcomes the error?

Also can you use the
PHP:
 code tags in your post :)
 
Last edited:
sorry php tags added.

i changed the header to "From: [email protected]" and it seems to work,

so why does the other code not work properly? As i need it to be able to accept what ever email is entered in the top text box.
 
Last edited:
Try it with

Code:
"From: $fromemail" . $headersep . "Reply-To: $email" . $headersep . "X-Mailer: chfeedback.php 2.15.0" .
 
Back
Top Bottom