nandos Posted May 29, 2011 Share Posted May 29, 2011 Hi, I'm trying to make an order form in php, basically I want the email to be sent to different email address in different email format, but I'm stuck with the code, can anyone help me with this, please? I've been trying to figure it out for a couple of days but I still can't solve it, my background is not in programming so, I think this must be really easy for programmers, but it's been causing me a headache. Below is the code that I've been stuck. <?PHP /* SUBJECT AND EMAIL VARIABLE */ $emailSubject = ' crystal ashley order form '; $webMaster = '[email protected], [email protected] '; /* gathering data variable */ $emailField = $_POST['email'] ; $recipientField = $_POST['recipient'] ; $nameField = $_POST['name'] ; $phoneField = $_POST['phone'] ; $codeField = $_POST['code'] ; $quantityField = $_POST['quantity'] ; $hearField = $_POST['hear'] ; $classField = $_POST['class'] ; $commentsField = $_POST['comments'] ; $body = <<<EOD <br><hr><br> Email : $email <br> Recipient : $recipient <br> Phone : $phone <br> Code : $code <br> Code : $code2 <br> Hear from : $hear <br> Interested in : $class <br> Comments : $comments <br> <br> EOD; $headers = "From : $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); Email : $email <br> Name : $name <br> Phone : $phone <br> Code : $code <br> Code : $code2 <br> Hear from : $hear <br> Interested in : $class <br> Comments : $comments <br> <br> EOD; $headers = "From : $email\r\n"; $headers = "To : $recipient\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); /*results rendered as html*/ $theResults = <<<EOD <html> <head> <title>Real Yoga Enquiry Form</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- body { background-color: #f1f1f1; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal; line-height: normal; font-weight: normal; color: #666666; text-decoration: none; } --> </style> </head> <div> <div align="left">Thank you for your interest! Your email will be answered very soon!</div> </div> </body> </html> EOD; echo "$theResults"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/237802-sending-different-email-format-to-different-address/ Share on other sites More sharing options...
seanlim Posted May 29, 2011 Share Posted May 29, 2011 You don't seem to have a clue about PHP, do you? Untested code: <?php /* SUBJECT AND EMAIL VARIABLE */ $emailSubject = ' crystal ashley order form '; $webMaster = '[email protected], [email protected] '; /* gathering data variable */ $emailField = $_POST['email'] ; $recipientField = $_POST['recipient'] ; $nameField = $_POST['name'] ; $phoneField = $_POST['phone'] ; $codeField = $_POST['code'] ; $quantityField = $_POST['quantity'] ; $hearField = $_POST['hear'] ; $classField = $_POST['class'] ; $commentsField = $_POST['comments'] ; $body = <<<EOD <br><hr><br> Email : $email <br> Recipient : $recipient <br> Phone : $phone <br> Code : $code <br> Code : $code2 <br> Hear from : $hear <br> Interested in : $class <br> Comments : $comments <br> <br> EOD; $headers = "From : $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); /*results rendered as html*/ $theResults = <<<EOD <html> <head> <title>Real Yoga Enquiry Form</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- body { background-color: #f1f1f1; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal; line-height: normal; font-weight: normal; color: #666666; text-decoration: none; } --> </style> </head> <div> <div align="left">Thank you for your interest! Your email will be answered very soon!</div> </div> </body> </html> EOD; $headers = "From : $email\r\n"; $headers = "To : $recipient\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($recipient, $emailSubject, $theResults, $headers); ?> Basically, I just removed a block of useless, repeated HTML code and sent the second mail using $theResults variable to $recipient. Quote Link to comment https://forums.phpfreaks.com/topic/237802-sending-different-email-format-to-different-address/#findComment-1222003 Share on other sites More sharing options...
nandos Posted May 29, 2011 Author Share Posted May 29, 2011 It works!! Thanks a lot Sean. Yes, I'm learning PHP at the momment, I'm a total beginner in PHP. Do you have a clue why the "from header" says "nobody" when I receive the reply mail in the mail inbox? Quote Link to comment https://forums.phpfreaks.com/topic/237802-sending-different-email-format-to-different-address/#findComment-1222038 Share on other sites More sharing options...
nandos Posted May 29, 2011 Author Share Posted May 29, 2011 does anybody know what code I have to type in if I want the $theResults and $theReply code not in the same email format <?PHP /* SUBJECT AND EMAIL VARIABLE */ $emailSubject = ' crystal ashley order form - squares '; $webMaster = '[email protected], [email protected] '; /* gathering data variable */ $emailField = $_POST['email'] ; $nameField = $_POST['name'] ; $phoneField = $_POST['phone'] ; $codeField = $_POST['code'] ; $quantityField = $_POST['quantity'] ; $hearField = $_POST['hear'] ; $classField = $_POST['class'] ; $commentsField = $_POST['comments'] ; $body = <<<EOD <br><hr><br> Email : $email <br> Name : $name <br> Phone : $phone <br> Code : $code <br> Code : $code2 <br> Hear from : $hear <br> Interested in : $class <br> Comments : $comments <br> <br> EOD; $headers = "From : $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); /*results rendered as html*/ $theResults = <<<EOD <html> <head> <title>Real Yoga Enquiry Form</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <div> <div align="left">Thank you for your interest! Your email will be answered very soon!</div> </div> </body> </html> EOD; $headers = "From : $email\r\n"; $headers = "To : $recipient\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($recipient, $emailSubject, $theResults, $headers); $theReply = <<<EOD <html> <head> <title>Real Yoga Enquiry Form</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <div> <div align="left">Thank you for your interest! Your email will be answered very soon!</div> </div> </body> </html> echo "$theReply"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/237802-sending-different-email-format-to-different-address/#findComment-1222057 Share on other sites More sharing options...
seanlim Posted May 30, 2011 Share Posted May 30, 2011 $headers = "From : $email\r\n"; $headers = "To : $recipient\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($recipient, $emailSubject, $theResults, $headers); In the second line in the above block of code, change the = to .=, which will effectively append the To field to the $headers variable. It is currently "overwriting" the From in the $headers variable, causing the mail to be from nobody. I don't understand your question... from what I understand, you are sending an email to the webmaster using $body, another email to the user using $theResults, and displaying a page to the user using $theReply. What are you trying to achieve? Quote Link to comment https://forums.phpfreaks.com/topic/237802-sending-different-email-format-to-different-address/#findComment-1222063 Share on other sites More sharing options...
nandos Posted May 30, 2011 Author Share Posted May 30, 2011 Thanksss alott for the help! I would like to send 2 email format to the buyer, one is to let them know that the order has been sent after the submit button, another one sent to their email to let them know that they will receive an order confirmation. Do you have any idea how i can do that? Quote Link to comment https://forums.phpfreaks.com/topic/237802-sending-different-email-format-to-different-address/#findComment-1222261 Share on other sites More sharing options...
seanlim Posted May 30, 2011 Share Posted May 30, 2011 You currently have 2 email formats: The first shows all the fields (email, name phone) and their values, and is currently sent to the webmaster. I'll assume that this is correct and require no further changes. The second displays the message "Thank you for your interest! Your email will be answered very soon!", and is sent to the email address stored in the variable $recipient. This format is also displayed in the browser because you do have an echo "$theReply"; at the bottom. Now, I'll assume that this second message is the same one that "(lets) them know that the order has been sent after the submit button". And where is the code/text for the "email to let them know that they will receive an order confirmation"? Will this email be sent at the same time as the previous email? Do let me know if my assumptions are wrong. Quote Link to comment https://forums.phpfreaks.com/topic/237802-sending-different-email-format-to-different-address/#findComment-1222292 Share on other sites More sharing options...
nandos Posted May 30, 2011 Author Share Posted May 30, 2011 Yes your assumption is right, the order confirmation email will be sent at the same time. I've made two 2 email formats, $theResults will be displayed on web browser after buyer click the submit button and $theReply will be sent to their email address, but I'm seeing this error message http://www.crystalashley.co.nz/order-form/contactformprocess-edit.php , do you know what's wrong with my code? I've amended the from header but I don't get why I'm still seeing nobody from "the mail from header" , please help thanksss <?PHP /* SUBJECT AND EMAIL VARIABLE */ $emailSubject = ' crystal ashley order form - squares '; $webMaster = '[email protected], [email protected] '; /* gathering data variable */ $emailField = $_POST['email'] ; $nameField = $_POST['name'] ; $phoneField = $_POST['phone'] ; $codeField = $_POST['code'] ; $quantityField = $_POST['quantity'] ; $hearField = $_POST['hear'] ; $classField = $_POST['class'] ; $commentsField = $_POST['comments'] ; $body = <<<EOD <br><hr><br> Email : $email <br> Name : $name <br> Phone : $phone <br> Code : $code <br> Hear from : $hear <br> Interested in : $class <br> Comments : $comments <br> <br> EOD; $headers = "From : $email\r\n"; $headers = "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); /*results rendered as html*/ $theResults = <<<EOD <html> <head> <title>crystal ashley form</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <div> <div align="left">Thank you for your interest! Your email will be answered very soon!</div> </div> </body> </html> $theReply = <<<EOD <html> <head> <title>crystal ashley form</title> </head> <div> <div align="left">Thank you for your interest! Your order confirmation will be sent very soon!</div> </div> </body> </html> EOD; $headers = "From : $webMaster\r\n"; $headers = "To : $recipient\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($recipient, $emailSubject, $theReply, $headers); echo "$theResults"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/237802-sending-different-email-format-to-different-address/#findComment-1222583 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.