respecttheplayer Posted July 27, 2009 Share Posted July 27, 2009 Right now i have a email form that I want to email to certain people depending on their answer, such as if productinfo = chucks then email to bob and jerry, but if productinfo = rotarytables then email to bob and tim but not jerry...... I hope you could follow that anyways my code is below for the email.php which processes the form. I have tried two ways doing this to show that I am trying, so maybe you can take a look at both and tell me where I am going wrong? One more thing from what I am noticing is that it's sticking on the first conditional statement and never acts to check if there are more conditions to be met so I know my code sucks now . PHP email.php version 1 <?php if($productinfo = 'rotarytables') { $to = ' [email protected], [email protected]'; $subject = "x.Net Contact Us from $fullname"; $message = "<p>stuff here</p>"; // must be double quoted to be able to use variables inside a string $headers = "From: [email protected]\r\n" . 'X-Mailer: PHP/' . phpversion() . "\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=utf-8\r\n" . "Content-Transfer-Encoding: 8bit\r\n\r\n"; } elseif($productinfo = 'chucks') { $to = ' [email protected], [email protected]'; $subject = "x.Net Contact Us from $fullname"; $message = "<p>Stuff here</p>"; // must be double quoted to be able to use variables inside a string $headers = "From: [email protected]\r\n" . 'X-Mailer: PHP/' . phpversion() . "\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=utf-8\r\n" . "Content-Transfer-Encoding: 8bit\r\n\r\n"; } else { // Send $sent = mail($to, $subject, $message, $headers) ; if($sent) {print "<center><p><span class=\"bold\">Thank you $fullname! Your mail was sent successfully, the details are as followed</span></p></center>"; } else {print "<p><span class=\"bold\">We encountered an error sending your mail, please go back to the <a href=\"contact.php\">contact form</a></span></p>"; } } ?> email.php version 2 <?php if($productinfo = 'rotarytables') { $to = ' [email protected], [email protected]'; $subject = "x.Net Contact Us from $fullname"; $message = "<p>Stuff here</p>"; // must be double quoted to be able to use variables inside a string $headers = "From: [email protected]\r\n" . 'X-Mailer: PHP/' . phpversion() . "\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=utf-8\r\n" . "Content-Transfer-Encoding: 8bit\r\n\r\n"; // Send $sent = mail($to, $subject, $message, $headers) ; if($sent) {print "<center><p><span class=\"bold\">Thank you $fullname! Your mail was sent successfully, the details are as followed</span></p></center>"; } else {print "<p><span class=\"bold\">We encountered an error sending your mail, please go back to the <a href=\"contact.php\">contact form</a></span></p>"; } } elseif($productinfo = 'chucks') { $to = ' [email protected], [email protected]'; $subject = "x.Net Contact Us from $fullname"; $message = "<p>Stuff Here</p>"; // must be double quoted to be able to use variables inside a string $headers = "From: [email protected]\r\n" . 'X-Mailer: PHP/' . phpversion() . "\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=utf-8\r\n" . "Content-Transfer-Encoding: 8bit\r\n\r\n"; // Send $sent = mail($to, $subject, $message, $headers) ; if($sent) {print "<center><p><span class=\"bold\">Thank you $fullname! Your mail was sent successfully, the details are as followed</span></p></center>"; } else {print "<p><span class=\"bold\">We encountered an error sending your mail, please go back to the <a href=\"contact.php\">contact form</a></span></p>"; } } ?> Let me know if I am not clear in my question and I 'll try my best to give you the information you may need, other than that, thanks a ton for taking a look at my code to teach me what I am doing wrong. Link to comment https://forums.phpfreaks.com/topic/167566-solved-email-with-conditional-not-working/ Share on other sites More sharing options...
abazoskib Posted July 27, 2009 Share Posted July 27, 2009 in the first example, why are you using an else to send the mail? if you take the send mail part out of the else it will work. in the second example, it looks fine as far as i can tell. the only thing i can suggest is check your headers. Link to comment https://forums.phpfreaks.com/topic/167566-solved-email-with-conditional-not-working/#findComment-883652 Share on other sites More sharing options...
vineld Posted July 27, 2009 Share Posted July 27, 2009 You're using assignment (=) instead of the equal to (==) operator which will make your statement true every time. Link to comment https://forums.phpfreaks.com/topic/167566-solved-email-with-conditional-not-working/#findComment-883655 Share on other sites More sharing options...
respecttheplayer Posted July 27, 2009 Author Share Posted July 27, 2009 Thanks vine, that was exactly it, I honestly do not know why they were there, I guess that's what I get when I am being lazy and do not really think things through, I got it working now. Thanks abazoskib for your answer as well in the reason why each example would not work. Thanks again guys. Link to comment https://forums.phpfreaks.com/topic/167566-solved-email-with-conditional-not-working/#findComment-883665 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.