codenoobie Posted August 4, 2008 Share Posted August 4, 2008 Hi everyone. I'm new here and I'm having issues with a PHP form. I am trying to send an auto response to the client, as well as the form results to myself. I have used the code below. The problem is that both the response and the results are being sent to the client. What could I be doing wrong? <?php //--------------------------Set these paramaters-------------------------- // Subject of email sent to you. $subject = 'Internet Request'; // Your email address. This is where the form information will be sent. $emailadd = 'myemail@comcast.net'; // Where to redirect after form is processed. $url = 'http://www.butneveragain.org/info/thankyou.html'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty. $req = '0'; // Email address put into Email Field $email_field = $_POST["Email"]; // --------------------------Do not edit below this line-------------------------- $auto_respond_subject = 'TEAM:BARIATRICS Informational Packet Request'; $auto_respond_body = "Thank you for requesting your free TEAM:BARIATRICS Informational Packet. \n You should recieve your packet within 5-10 business days.\n If you would like additional information, call 574.537.TEAM or visit us online at www.butneveragain.org."; mail($email_field, $auto_respond_subject, $auto_respond_body); $text = "Results from form:\n\n"; $space = ' '; $line = ' '; foreach ($_POST as $key => $value) { if ($req == '1') { if ($value == '') { echo "$key is empty"; die; } } $j = strlen($key); if ($j >= 20) { echo "Name of form element $key cannot be longer than 20 characters"; die; } $j = 20 - $j; for ($i = 1; $i <= $j; $i++) { $space .= ' '; } $value = str_replace('\n', "$line", $value); $conc = "{$key}:$space{$value}$line"; $text .= $conc; $space = ' '; } mail($email_field, $subject, $text, "From: TEAM:BARIATRICS"); echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/118116-help-with-php-auto-response-form/ Share on other sites More sharing options...
codenoobie Posted August 4, 2008 Author Share Posted August 4, 2008 Also, here is my form code: <div class="mainContentInfo"> <img src="../images/info.jpg" width="467" height="14" style="padding-top:20px;"/><br/><br/> <span class="copy">To get your Informational Packet, simply fill out the form below or call 574.537.TEAM.</span> <p> <form id="form1" name="form1" method="post" action="http://www.butneveragain.org/info/mailer.php"> Name:<label> <input name="Name" type="text" class="style1" id="Name" size="30" /> </label><br/> Email:<label> <input name="Email" type="text" class="style1" id="Email" size="30" /> </label><br/> <label> <input name="Submit2" type="reset" class="style1" value="Reset" /> <input name="Submit" type="submit" class="style1" value="Submit" /> </form> </p> </div> Quote Link to comment https://forums.phpfreaks.com/topic/118116-help-with-php-auto-response-form/#findComment-607682 Share on other sites More sharing options...
DeanWhitehouse Posted August 4, 2008 Share Posted August 4, 2008 The from email must be an email registered on the hosting Quote Link to comment https://forums.phpfreaks.com/topic/118116-help-with-php-auto-response-form/#findComment-607684 Share on other sites More sharing options...
.josh Posted August 4, 2008 Share Posted August 4, 2008 both of your mail() function calls are using $email_field as the to argument I assume one of them should be $emailadd Quote Link to comment https://forums.phpfreaks.com/topic/118116-help-with-php-auto-response-form/#findComment-607685 Share on other sites More sharing options...
codenoobie Posted August 4, 2008 Author Share Posted August 4, 2008 Thank you, Crayon Violent - Do you have any idea which one should be changed? I'm pretty new to PHP. Quote Link to comment https://forums.phpfreaks.com/topic/118116-help-with-php-auto-response-form/#findComment-607687 Share on other sites More sharing options...
.josh Posted August 4, 2008 Share Posted August 4, 2008 well if I had to take a guess I'd say you want to change the 2nd one, based on the email contents being sent, but that's just a guess. I mean, I don't work for you or your company or whatnot. Quote Link to comment https://forums.phpfreaks.com/topic/118116-help-with-php-auto-response-form/#findComment-607690 Share on other sites More sharing options...
codenoobie Posted August 4, 2008 Author Share Posted August 4, 2008 Nevermind, I figured it out! Thank you so much. One more quick question: In the "From" category when the client recieves the response, it shows my server information. Is there a way to change that to "TEAM:BARIATRICS" instead? Quote Link to comment https://forums.phpfreaks.com/topic/118116-help-with-php-auto-response-form/#findComment-607695 Share on other sites More sharing options...
.josh Posted August 4, 2008 Share Posted August 4, 2008 The from email must be an email registered on the hosting Quote Link to comment https://forums.phpfreaks.com/topic/118116-help-with-php-auto-response-form/#findComment-607699 Share on other sites More sharing options...
DeanWhitehouse Posted August 4, 2008 Share Posted August 4, 2008 Unless you use PHPmailer Quote Link to comment https://forums.phpfreaks.com/topic/118116-help-with-php-auto-response-form/#findComment-607700 Share on other sites More sharing options...
codenoobie Posted August 4, 2008 Author Share Posted August 4, 2008 I'm sorry. I read that but I didn't understand it because I'm so new at all of this. It currently reads "ghsfiles@box394.bluehost.com" in the "from" category. I'm hoping to find a way to get it to read something else. I'll keep working on it. Quote Link to comment https://forums.phpfreaks.com/topic/118116-help-with-php-auto-response-form/#findComment-607701 Share on other sites More sharing options...
codenoobie Posted August 4, 2008 Author Share Posted August 4, 2008 I think I have to add headers to the script. Quote Link to comment https://forums.phpfreaks.com/topic/118116-help-with-php-auto-response-form/#findComment-607709 Share on other sites More sharing options...
DeanWhitehouse Posted August 4, 2008 Share Posted August 4, 2008 when u send a email using the mail(); function , it is sent through the servers SMTP , and in effect must be sent from an email set up on the server, unless you use PHP mailer. Quote Link to comment https://forums.phpfreaks.com/topic/118116-help-with-php-auto-response-form/#findComment-607712 Share on other sites More sharing options...
codenoobie Posted August 4, 2008 Author Share Posted August 4, 2008 That makes sense. I'm reading up on PHPMailer to learn more about it and understand it. This is the first I've heard about it. Quote Link to comment https://forums.phpfreaks.com/topic/118116-help-with-php-auto-response-form/#findComment-607732 Share on other sites More sharing options...
codenoobie Posted August 4, 2008 Author Share Posted August 4, 2008 Ok, I'm in trouble here. I'm going to have to really learn PHPMailer as soon as I can. But, I'm really under the gun timewise (I'm pregnant and due tomorrow - if I don't get this site done by the time this baby comes I'm in real trouble with my boss.) Is there anyway to add headers to this code that will customize the "from" email address to say "TEAM:BARIATRICS" instead of "ghsfiles@box394.bluehost.com" easily? I can't figure it out without help. I've been trying to all day and I'm so new at this I'm not having luck at all: <?php //--------------------------Set these paramaters-------------------------- // Subject of email sent to you. $subject = 'TEAM:BARIATRICS Informational Packet Request'; // Your email address. This is where the form information will be sent. $emailadd = 'aubreyburkhart@comcast.net'; // Where to redirect after form is processed. $url = 'http://www.butneveragain.org/info/thankyou.html'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty. $req = '0'; // Email address put into Email Field $email_field = $_POST["Email"]; // --------------------------Do not edit below this line-------------------------- $auto_respond_subject = 'TEAM:BARIATRICS Informational Packet Request'; $auto_respond_body = "Thank you for requesting your free TEAM:BARIATRICS Informational Packet. \n You should recieve your packet within 5-10 business days.\n If you would like additional information, call 574.537.TEAM or visit us online at www.butneveragain.org."; mail($email_field, $auto_respond_subject, $auto_respond_body); $text = "Results from form:\n\n"; $space = ' '; $line = ' '; foreach ($_POST as $key => $value) { if ($req == '1') { if ($value == '') { echo "$key is empty"; die; } } $j = strlen($key); if ($j >= 20) { echo "Name of form element $key cannot be longer than 20 characters"; die; } $j = 20 - $j; for ($i = 1; $i <= $j; $i++) { $space .= ' '; } $value = str_replace('\n', "$line", $value); $conc = "{$key}:$space{$value}$line"; $text .= $conc; $space = ' '; } mail($emailadd, $subject, $text, "From: Online Request"); echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/118116-help-with-php-auto-response-form/#findComment-607968 Share on other sites More sharing options...
DeanWhitehouse Posted August 4, 2008 Share Posted August 4, 2008 Thats the most you can do without PHP mailer <?php //--------------------------Set these paramaters-------------------------- // Subject of email sent to you. $subject = 'TEAM:BARIATRICS Informational Packet Request'; // Your email address. This is where the form information will be sent. $emailadd = 'aubreyburkhart@comcast.net'; // Where to redirect after form is processed. $url = 'http://www.butneveragain.org/info/thankyou.html'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty. $req = '0'; // Email address put into Email Field $email_field = $_POST["Email"]; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'From: TEAM:BARIATRICS <ghsfiles@box394.bluehost.comcom>'; // --------------------------Do not edit below this line-------------------------- $auto_respond_subject = 'TEAM:BARIATRICS Informational Packet Request'; $auto_respond_body = "Thank you for requesting your free TEAM:BARIATRICS Informational Packet. \n You should recieve your packet within 5-10 business days.\n If you would like additional information, call 574.537.TEAM or visit us online at www.butneveragain.org."; mail($email_field, $auto_respond_subject, $auto_respond_body,$header); $text = "Results from form:\n\n"; $space = ' '; $line = ' '; foreach ($_POST as $key => $value) { if ($req == '1') { if ($value == '') { echo "$key is empty"; die; } } $j = strlen($key); if ($j >= 20) { echo "Name of form element $key cannot be longer than 20 characters"; die; } $j = 20 - $j; for ($i = 1; $i <= $j; $i++) { $space .= ' '; } $value = str_replace('\n', "$line", $value); $conc = "{$key}:$space{$value}$line"; $text .= $conc; $space = ' '; } mail($emailadd, $subject, $text, "From: Online Request"); echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/118116-help-with-php-auto-response-form/#findComment-607978 Share on other sites More sharing options...
codenoobie Posted August 4, 2008 Author Share Posted August 4, 2008 Yikes - Ok, thank you Quote Link to comment https://forums.phpfreaks.com/topic/118116-help-with-php-auto-response-form/#findComment-607980 Share on other sites More sharing options...
DeanWhitehouse Posted August 4, 2008 Share Posted August 4, 2008 hang on this line is wrong ,soz mail($email_field, $auto_respond_subject, $auto_respond_body,$header); should be mail($email_field, $auto_respond_subject, $auto_respond_body,$headers); Quote Link to comment https://forums.phpfreaks.com/topic/118116-help-with-php-auto-response-form/#findComment-608003 Share on other sites More sharing options...
codenoobie Posted August 4, 2008 Author Share Posted August 4, 2008 Hi Blade, I'm getting this error with the new code: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/ghsfiles/public_html/butneveragain/info/mailer.php on line 4 Quote Link to comment https://forums.phpfreaks.com/topic/118116-help-with-php-auto-response-form/#findComment-608023 Share on other sites More sharing options...
DeanWhitehouse Posted August 4, 2008 Share Posted August 4, 2008 whats line 4? Quote Link to comment https://forums.phpfreaks.com/topic/118116-help-with-php-auto-response-form/#findComment-608026 Share on other sites More sharing options...
codenoobie Posted August 4, 2008 Author Share Posted August 4, 2008 $subject = 'TEAM:BARIATRICS Informational Packet Request'; Quote Link to comment https://forums.phpfreaks.com/topic/118116-help-with-php-auto-response-form/#findComment-608029 Share on other sites More sharing options...
DeanWhitehouse Posted August 4, 2008 Share Posted August 4, 2008 whats the line before ? Quote Link to comment https://forums.phpfreaks.com/topic/118116-help-with-php-auto-response-form/#findComment-608035 Share on other sites More sharing options...
codenoobie Posted August 4, 2008 Author Share Posted August 4, 2008 Here's all of the code... (DarkWater is taking a look at it too) He said he's not getting any errors but when I fill out the form on the website I do. This is getting really weird... <?php //--------------------------Set these paramaters-------------------------- // Subject of email sent to you. $subject = 'TEAM:BARIATRICS Informational Packet Request'; // Your email address. This is where the form information will be sent. $emailadd = 'aubreyburkhart@comcast.net'; // Where to redirect after form is processed. $url = 'http://www.butneveragain.org/info/thankyou.html'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty. $req = '0'; // Email address put into Email Field $email_field = $_POST["Email"]; //Here is where I set the headers, you can add more if ever necessary $headers = "From: Team:Bariatrics <ghsfiles@box394.bluehost.com>"; // --------------------------Do not edit below this line-------------------------- $auto_respond_subject = 'TEAM:BARIATRICS Informational Packet Request'; $auto_respond_body = "Thank you for requesting your free TEAM:BARIATRICS Informational Packet. \n You should recieve your packet within 5-10 business days.\n If you would like additional information, call 574.537.TEAM or visit us online at www.butneveragain.org."; mail($email_field, $auto_respond_subject, $auto_respond_body, $headers); $text = "Results from form:\n\n"; $space = ' '; $line = ' '; foreach ($_POST as $key => $value) { if ($req == '1') { if ($value == '') { echo "$key is empty"; die; } } $j = strlen($key); if ($j >= 20) { echo "Name of form element $key cannot be longer than 20 characters"; die; } $j = 20 - $j; for ($i = 1; $i <= $j; $i++) { $space .= ' '; } $value = str_replace('\n', "$line", $value); $conc = "{$key}:$space{$value}$line"; $text .= $conc; $space = ' '; } mail($emailadd, $subject, $text, "From: Online Request"); echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/118116-help-with-php-auto-response-form/#findComment-608037 Share on other sites More sharing options...
DeanWhitehouse Posted August 4, 2008 Share Posted August 4, 2008 looks fine to me Quote Link to comment https://forums.phpfreaks.com/topic/118116-help-with-php-auto-response-form/#findComment-608048 Share on other sites More sharing options...
codenoobie Posted August 4, 2008 Author Share Posted August 4, 2008 I know it... This is really strange. If I find a fix, I'll post it. Thanks again for all of your help. Quote Link to comment https://forums.phpfreaks.com/topic/118116-help-with-php-auto-response-form/#findComment-608054 Share on other sites More sharing options...
DeanWhitehouse Posted August 4, 2008 Share Posted August 4, 2008 k, a way to help is to put error_reporting(E_ALL); at the top of the page Quote Link to comment https://forums.phpfreaks.com/topic/118116-help-with-php-auto-response-form/#findComment-608060 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.