damion Posted January 4, 2015 Share Posted January 4, 2015 I have a site that allows people to register for a fee. It is a very basic form asking for name and contact info. After they fill out the form and submit it, they are brought to paypal to make their payment. After paying, the form data is sent to the admin and to the customer. What is very strange is the form seems to work perfectly most of the time, except sometimes: 1. the email is not received by the admin (not sure if the buyer is getting their copy though). 2. if multiple email addresses in the admin settings to receive it (comma separated), sometimes some receive it, but some do not! The owner of the site said they do check their spam and we've tried different email addresses for the admin (gmail, outlook, yahoo, etc..) and it has occurred on all of them, no rhyme or reason. Do you see anything wrong with my form below that would have this intermittent issue? Also, anyone suggest how I can add headers to this so that the 'from' won't default to the host server name? The file admin.php contains the email variable $admin_email <?php require '../admin.php'; session_start(); if (!isset($_SESSION['order_id']) || empty($_SESSION['order_id'])) { header('Location: ../../'); } // admin email mail($admin_email, 'Website form submitted', 'Visitor information. Registration: ' . $_SESSION['order_id']."\r\n".' First Name: ' .$_SESSION['fname'].' Last Name: ' .$_SESSION['lname'].' Email: ' .$_SESSION['email'].' Phone: ' .$_SESSION['phone']); // visitor email $to = $_SESSION['email']; mail($to, 'Thank you for registering', 'Review your submission below. Please contact us if you need further assistance. Registration: ' . $_SESSION['order_id']."\r\n".' First Name: ' .$_SESSION['fname'].' Last Name: ' .$_SESSION['lname'].' Email: ' .$_SESSION['email'].' Phone: ' .$_SESSION['phone']); session_destroy(); ?> Quote Link to comment Share on other sites More sharing options...
Barand Posted January 4, 2015 Share Posted January 4, 2015 http://php.net/manual/en/function.mail.php see example #2 Quote Link to comment Share on other sites More sharing options...
wezhind Posted January 5, 2015 Share Posted January 5, 2015 Hi there, This isn't an answer to your issue, but I'm wondering if you could assign the mail function to a variable and then test the variable to see if sent... this may help with debugging the issue (it also may not). I'd do something like: // admin email $send_admin_email = mail($admin_email, 'Website form submitted', 'Visitor information. Registration: ' . $_SESSION['order_id']."\r\n".' First Name: ' .$_SESSION['fname'].' Last Name: ' .$_SESSION['lname'].' Email: ' .$_SESSION['email'].' Phone: ' .$_SESSION['phone']); if ($send_admin_email) { //the mail function worked } I realise this doesn't answer your question, but it may help you debug if you blast a few emails out and check the values of the ones that fail. Good luck. Quote Link to comment Share on other sites More sharing options...
damion Posted January 5, 2015 Author Share Posted January 5, 2015 http://php.net/manual/en/function.mail.php see example #2 I actually tried to follow that before (and also tried example #3). The problem I was having when trying to implement them was that they were appearing literally in the email as text. And of course since it was not parsing it did not change the 'from'. How would you go about adding it in my case? Can you show me? Thanks Quote Link to comment Share on other sites More sharing options...
damion Posted January 5, 2015 Author Share Posted January 5, 2015 Hi there, This isn't an answer to your issue, but I'm wondering if you could assign the mail function to a variable and then test the variable to see if sent... this may help with debugging the issue (it also may not). I'd do something like: // admin email $send_admin_email = mail($admin_email, 'Website form submitted', 'Visitor information. Registration: ' . $_SESSION['order_id']."\r\n".' First Name: ' .$_SESSION['fname'].' Last Name: ' .$_SESSION['lname'].' Email: ' .$_SESSION['email'].' Phone: ' .$_SESSION['phone']); if ($send_admin_email) { //the mail function worked } I realise this doesn't answer your question, but it may help you debug if you blast a few emails out and check the values of the ones that fail. Good luck. Hmm... I'm going to play around with that. But maybe I won't make it send an email if the condition is true I'm almost convinced the problem is the user not finding the email in their spam. Every test I ran with my email addresses plugged in I always got them! But I need to be sure, and it's a very aggravating and time consuming issue. Thanks! Quote Link to comment Share on other sites More sharing options...
ginerjm Posted January 5, 2015 Share Posted January 5, 2015 Do you have php error checking enabled to be sure your script is free of errors? As for testing the result of the mail call - I find that it pretty much always comes back true even if the mail is never sent. As for the headers showing up in the message - you probably did not format the mail call correctly. Try building the message body from all those parts outside of the call and then just pass in 4 vars to the call: $to, $subject, $msg, $hdrs. Quote Link to comment Share on other sites More sharing options...
damion Posted January 5, 2015 Author Share Posted January 5, 2015 Do you have php error checking enabled to be sure your script is free of errors? As for testing the result of the mail call - I find that it pretty much always comes back true even if the mail is never sent. As for the headers showing up in the message - you probably did not format the mail call correctly. Try building the message body from all those parts outside of the call and then just pass in 4 vars to the call: $to, $subject, $msg, $hdrs. Ah, thanks for the tip about error checking. It seems that when my form is submitted the page it submits to contains 2 warnings and 1 notice. The notice is an undefined variable, and the warnings are for headers already sent. The problem is the header-location is in 2 areas of my page in If statements and I don't know how to get around that. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted January 5, 2015 Share Posted January 5, 2015 The way to avoid a problem with headers is to practice good code organization in your scripts. Do your output from one place, after you have processed thru all your logic. That way if your logic wants to send you somewhere else it can do so, since you will not have output anything at that point. Fix those errors! Quote Link to comment Share on other sites More sharing options...
damion Posted January 5, 2015 Author Share Posted January 5, 2015 I guess I'll be looking for a coder then. I took this about as far as I know how. Any interest in fixing a badly crippled script for almost next to nothing but slightly more than free?? Quote Link to comment Share on other sites More sharing options...
ginerjm Posted January 5, 2015 Share Posted January 5, 2015 Not in this forum. See other ones. Quote Link to comment Share on other sites More sharing options...
wezhind Posted January 5, 2015 Share Posted January 5, 2015 You could start by moving the: require '../admin.php'; to after the session_start(); in the above code. This may resolve one of your 'headers already sent' errors. Good luck. Quote Link to comment 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.