carley_bell Posted February 3, 2009 Share Posted February 3, 2009 Hi, I tested my form mailer using a "fixed" email address to make sure it works, which it did. Then I changed the "fixed" email address to a database query that gets the email address associated with the row id posted from a previous form- and I get the following error: Warning: mail() [function.mail]: SMTP server response: 503 RCPT first (#5.5.1) in D:\Hosting\3709681\html\mailer.php on line 49. I echoed the results of the email address query and it is returning the correct email address, so I believe the problem is with the "$emailadd = $email['field_7'];" part. what am I doing wrong here? p.s. I know I can have the row id translated to an email address in the form, but it can be seen when you view the source code. <?php // connect to database include("./config.inc.php"); $row = $_POST['email']; // get email address from row number $query = "SELECT field_1,field_7 FROM `".$db_table."` WHERE '$row' = id"; $result = mysql_query($query); $email = mysql_fetch_assoc($result); //--------------------------Set paramaters-------------------------- // Subject of email sent to you. $subject = 'Results from Contact form'; // Your email address. This is where the form information will be sent. $emailadd = $email['field_7']; // Where to redirect after form is processed. $url = ''; // 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'; // --------------------------End set parameters-------------------------- $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: '.$emailadd.''); echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; ?> Link to comment https://forums.phpfreaks.com/topic/143545-solved-form-mailer-issue/ Share on other sites More sharing options...
gevans Posted February 3, 2009 Share Posted February 3, 2009 I'm confused by this bit; $row = $_POST['email']; // get email address from row number $query = "SELECT field_1,field_7 FROM `".$db_table."` WHERE '$row' = id"; $result = mysql_query($query); What value is initially assigned to $row (what is $_POST['email']) In your query is id the field of unique identifiers? Link to comment https://forums.phpfreaks.com/topic/143545-solved-form-mailer-issue/#findComment-753093 Share on other sites More sharing options...
carley_bell Posted February 3, 2009 Author Share Posted February 3, 2009 I have a database search that displays the results with a contact button. The contact button is a mini form with hidden field that sends the row id to the next form where the user enters their email address and message. The hidden row id field on that form is named 'email' Link to comment https://forums.phpfreaks.com/topic/143545-solved-form-mailer-issue/#findComment-753100 Share on other sites More sharing options...
carley_bell Posted February 3, 2009 Author Share Posted February 3, 2009 i can be confusing at times so I will just post the code for the form too... <div align="center"><b>CONTACT</b></div> <form name="contact_user2" method="POST" action="mailer.php"> <div align="left"> <b>Email</b> (enter your email address)<br> <input name="email" type="text" size="30" maxlength="40"><br> <b>Message</b><br> <textarea name="mesg" cols="30" rows="5" maxlength="250"></textarea><br> </div> <?php include("./config.inc.php"); $row = $_POST['row']; // get email from row number $query = "SELECT field_1,field_7 FROM `".$db_table."` WHERE '$row' = id"; $result = mysql_query($query); $email = mysql_fetch_assoc($result); ?> <input name="subject" type="hidden" value="Information regarding part # <?php echo $email['field_1']; ?>"> <input name="email" type="hidden" value="<?php echo $row; ?>"> <input type="submit" name="submit" value="Send" /> </form> Link to comment https://forums.phpfreaks.com/topic/143545-solved-form-mailer-issue/#findComment-753113 Share on other sites More sharing options...
gevans Posted February 3, 2009 Share Posted February 3, 2009 Was just making sure.... the naming of things were causing worries. Before; mail($emailadd, $subject, $text, 'From: '.$emailadd.''); can you do this... <?php echo <<<EOF $emailadd <br /> $subject <br /> $text <br /> From: $emailadd EOF; exit; and post what was printed to screen Link to comment https://forums.phpfreaks.com/topic/143545-solved-form-mailer-issue/#findComment-753116 Share on other sites More sharing options...
gevans Posted February 3, 2009 Share Posted February 3, 2009 Hold everything... you have two fields in your form called 'email' Link to comment https://forums.phpfreaks.com/topic/143545-solved-form-mailer-issue/#findComment-753118 Share on other sites More sharing options...
carley_bell Posted February 3, 2009 Author Share Posted February 3, 2009 ok.. it gives me this: [email protected] Results from Contact form Results from form: email: 44 mesg: test subject: Information regarding # TEST submit: Send From: [email protected] Link to comment https://forums.phpfreaks.com/topic/143545-solved-form-mailer-issue/#findComment-753125 Share on other sites More sharing options...
gevans Posted February 3, 2009 Share Posted February 3, 2009 Hold everything... you have two fields in your form called 'email' Link to comment https://forums.phpfreaks.com/topic/143545-solved-form-mailer-issue/#findComment-753128 Share on other sites More sharing options...
carley_bell Posted February 3, 2009 Author Share Posted February 3, 2009 oooh.... ok I missed that... I changed the second email on the form and processor and it is still giving me the same error Link to comment https://forums.phpfreaks.com/topic/143545-solved-form-mailer-issue/#findComment-753130 Share on other sites More sharing options...
gevans Posted February 3, 2009 Share Posted February 3, 2009 ok, put; var_dump($_POST); exit; at the top of your mail code and post the result Link to comment https://forums.phpfreaks.com/topic/143545-solved-form-mailer-issue/#findComment-753135 Share on other sites More sharing options...
carley_bell Posted February 3, 2009 Author Share Posted February 3, 2009 I get: array(5) { ["email"]=> string(11) "[email protected]" ["mesg"]=> string(4) "test" ["subject"]=> string(48) "Information regarding part # TEST" ["rowemail"]=> string(2) "44" ["submit"]=> string(4) "Send" } Link to comment https://forums.phpfreaks.com/topic/143545-solved-form-mailer-issue/#findComment-753139 Share on other sites More sharing options...
gevans Posted February 3, 2009 Share Posted February 3, 2009 I've found this: CLICKY Sounds like it could be a problem with the server reference in your php.ini Link to comment https://forums.phpfreaks.com/topic/143545-solved-form-mailer-issue/#findComment-753150 Share on other sites More sharing options...
carley_bell Posted February 3, 2009 Author Share Posted February 3, 2009 I am using godaddy.com... I am pretty sure I dont have access to the php.ini file So the server is fine with me manually putting and email address in but it doesn't like me getting the address from a database? Link to comment https://forums.phpfreaks.com/topic/143545-solved-form-mailer-issue/#findComment-753161 Share on other sites More sharing options...
gevans Posted February 3, 2009 Share Posted February 3, 2009 If you tell godaddy the error number (well the whole error) they should/will fix this for you if it is a php.ini error Link to comment https://forums.phpfreaks.com/topic/143545-solved-form-mailer-issue/#findComment-753166 Share on other sites More sharing options...
gevans Posted February 3, 2009 Share Posted February 3, 2009 Just to satisfy my curiosities on the issue can you change this line; mail($emailadd, $subject, $text, 'From: '.$emailadd.''); to this; if(mail($emailadd, "test", "test")){ die('mail sent'); } else { die('mail not sent'); } Link to comment https://forums.phpfreaks.com/topic/143545-solved-form-mailer-issue/#findComment-753174 Share on other sites More sharing options...
carley_bell Posted February 3, 2009 Author Share Posted February 3, 2009 it says "mail sent" Link to comment https://forums.phpfreaks.com/topic/143545-solved-form-mailer-issue/#findComment-753180 Share on other sites More sharing options...
carley_bell Posted February 3, 2009 Author Share Posted February 3, 2009 OK.... I just got an email with the suject "test" and message "test".... why did this work? ??? Link to comment https://forums.phpfreaks.com/topic/143545-solved-form-mailer-issue/#findComment-753187 Share on other sites More sharing options...
gevans Posted February 3, 2009 Share Posted February 3, 2009 why did this work? ??? haha, im working a little bit blind bare with me.... now change it to this if(mail($emailadd, $subject, $text)){ die('mail sent'); } else { die('mail not sent'); } Link to comment https://forums.phpfreaks.com/topic/143545-solved-form-mailer-issue/#findComment-753189 Share on other sites More sharing options...
carley_bell Posted February 3, 2009 Author Share Posted February 3, 2009 I got this error: Warning: mail() [function.mail]: SMTP server response: 451 See http://pobox.com/~djb/docs/smtplf.html. in D:\Hosting\html\mailer.php on line 56 mail not sent I had that one before, something about Bare LF's? Link to comment https://forums.phpfreaks.com/topic/143545-solved-form-mailer-issue/#findComment-753200 Share on other sites More sharing options...
gevans Posted February 3, 2009 Share Posted February 3, 2009 The problem at the moment is the way you're using carriag returns and line feeds, try the following (full code); <?php // connect to database include("./config.inc.php"); $row = $_POST['email']; // get email address from row number $query = "SELECT field_1,field_7 FROM `".$db_table."` WHERE '$row' = id"; $result = mysql_query($query); $email = mysql_fetch_assoc($result); //--------------------------Set paramaters-------------------------- // Subject of email sent to you. $subject = 'Results from Contact form'; // Your email address. This is where the form information will be sent. $emailadd = $email['field_7']; // Where to redirect after form is processed. $url = ''; // 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'; // --------------------------End set parameters-------------------------- $text = "Results from form:\r\n\r\n"; $space = ' '; 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 .= ' '; } $conc = "{$key}:{$space}{$value}\r\n"; $text .= $conc; $space = ' '; } if(mail($emailadd, $subject, $text)){ die('mail sent'); } else { die('mail not sent'); } echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; ?> Link to comment https://forums.phpfreaks.com/topic/143545-solved-form-mailer-issue/#findComment-753208 Share on other sites More sharing options...
carley_bell Posted February 3, 2009 Author Share Posted February 3, 2009 BRILLIANT!!! YOU ARE A GENIUS!!! THANK YOU SOOOOOO MUCH!!!! Link to comment https://forums.phpfreaks.com/topic/143545-solved-form-mailer-issue/#findComment-753211 Share on other sites More sharing options...
gevans Posted February 3, 2009 Share Posted February 3, 2009 You can change this; if(mail($emailadd, $subject, $text)){ die('mail sent'); } else { die('mail not sent'); } to this.... if(!mail($emailadd, $subject, $text)){ die('There was an error sending the email.'); } and we can try and add the from field back in; if(!mail($emailadd, $subject, $text, "FROM: [email protected]")){ die('There was an error sending the email.'); } Link to comment https://forums.phpfreaks.com/topic/143545-solved-form-mailer-issue/#findComment-753213 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.