Page 1 of 1
Auto Send Email
Posted: Sat Mar 10, 2012 10:26 pm
by webbiz
I apologize for asking such a novice question, but I'm not much experienced in PHP and really need to solve this.
I have a PHP order form.
When the user fills it out and clicks on Submit, I receive an email through FormMail. All this works well for couple years now.
Sometimes the user enters his email address wrong and I am not able to get back to this person, and this person is waiting and thinks I am not trying to contact without knowing he provided a bad email address.
So this is what I am thinking.
Right now, after the user clicks on Submit, another PHP webpage is called up. It is "order-received.php". This page just tells the user to make sure to whitelist my email address so that when I do respond, it will not go to his spam box.
So I am thinking that when this page is called up, it not only tells him to whitelist my email address, but it tells him that an email has been sent to him and if he does not get it in a few minutes that he needs to contact me asap. Therefore, I would like this page (or how ever it can be done) to automatically send him a text message.
How is this done? I'm not sure the procedure.
Thanks.
Re: Auto Send Email
Posted: Sat Mar 10, 2012 10:57 pm
by califdon
Do you really mean a text message?? An SMS? To a phone number? Do all your customers have smart phones?
As an alternative suggestion, how about just popping up a small window that says that the order has been received and if he/she does not receive email confirmation within 10 minutes (or whatever), contact you by phone (or however you want to handle it)? Or you could just have that information in a <div> with the display property set to "none" until the Submit button is clicked, then your Javascript can change the display property to "block" so it suddenly appears. Or you could use jQuery to do something a little fancier, like fade-in. My point is that I think it is over-kill to load a whole new web page for something like that.
Are you requiring the user to enter their email twice? Do you validate that at least the email address is correctly formed? Needless to say, that doesn't assure that it's an active email account, or that the recipient isn't using some kind of whitelist, as you described, but you should at least determine that it's a possible address.
Re: Auto Send Email
Posted: Sat Mar 10, 2012 11:07 pm
by webbiz
No, not a SMS text message, but an email text message (as opposed to a HTML email message). Sorry for the confusion.
Your alternate suggestion is similar to what I am trying to do.
Right now, a window already opens up (it is a php webpage actually) and says that the order has been sent and that we will respond within 24 hours.
The problem is that sometimes when we try to respond, we get the email kicked back because they accidentally entered a wrong email address.
So what I'd like to happen is that when that window opens and tells them that their order has been sent (as well as tell them to be sure to whitelist our email address), I would also like a confirmation email to be sent to them about their order (and perhaps provide some additional information).
So my question is how to make the window that pops up also send an email message?
Thanks.
Re: Auto Send Email
Posted: Sat Mar 10, 2012 11:46 pm
by califdon
Oh, now I understand what you were asking. I assume that your website is hosted at some commercial hosting company. If that is so, they undoubtedly have a local SMTP server, as well (that's an outgoing mail server). Then it is extremely simple to send emails. Just Google php mail and you will find a bunch of tutorials on using the built-in PHP function mail().
Re: Auto Send Email
Posted: Sat Mar 10, 2012 11:53 pm
by webbiz
I googled that before I asked here.
I did not find anything that was dumbed down enough for me to figure out.
I thought maybe someone here could perhaps point me directly to what I need to do.
The stuff I saw deals with writing a form, or creating a php that does nothing but send out an email.
I'm trying to modify and existing response page (php) to not only display what it does right now, but to also send an email.
1. How does the other webpage that I open up get the email address?
2. Once it gets the email address, how do you trigger the email function?
The sites I visited does not deal directly with this issue of having an existing page that opens up, but with creating a form or hard coding a message.
Again, I'm not a php programmer. I'm looking to modify existing php code that I did not write (but paid to have written for me a few years ago). As I am a programmer of other languages, it isn't beyond my capability to understand instructions provided to me. However, to do this little task I can't justify learning a whole new language. Once this task is finished, I may not do any php code for another few years.

Re: Auto Send Email
Posted: Sun Mar 11, 2012 12:12 am
by califdon
I understand what you are saying, but I think it may be difficult to find anyone here willing to undertake to revise a script for you in the forum. It would be a rather simple job, just a few lines of code, but exactly what that code is and where it goes depends on the other code that is already there, as I'm sure you, as a programmer, can appreciate. If you wanted to learn PHP and do it yourself, it would be easy for you to find someone willing to teach you, but not many people here want to write the code for you. I think most people here feel there's not much reward in doing that. My best advice to you is to find a competent PHP developer whom you can hire to do it. That way, you'll get it done right and have a resource in case you need it later.
Re: Auto Send Email
Posted: Sun Mar 11, 2012 12:25 pm
by webbiz
"I think most people here feel there's not much reward in doing that. "
What reward does anyone expect from helping anyone else? I'm a bit puzzled by that statement.
I don't want anyone to write or modify my code. That's annoying lazy.
I'm looking for a bit of direction.
In most languages, you trigger a routine by simply calling the name of the routine. But in PHP, I don't see how to trigger the functions or time 'when' it should be triggered. The pages I've looked at seems to put these functions in not any particular order, nor do I see any "calling" routines.
And does someone actually have to see my code or rewrite my code to tell me how you get an email address from one page to another?
Anyway, I appreciate your comments.
Thanks and take care.

Re: Auto Send Email
Posted: Sun Mar 11, 2012 1:46 pm
by califdon
webbiz wrote:"I think most people here feel there's not much reward in doing that. "
What reward does anyone expect from helping anyone else? I'm a bit puzzled by that statement.
For me, at least (and I think I am not alone), the reward comes from helping someone learn something useful, not in doing their task for them. Perhaps I am influenced by having taught in college for a decade or so.
webbiz wrote:I don't want anyone to write or modify my code. That's annoying lazy.
I'm looking for a bit of direction.
I'm gratified to know that you feel that way. I think maybe we're both misreading each other's intentions here.
webbiz wrote:In most languages, you trigger a routine by simply calling the name of the routine. But in PHP, I don't see how to trigger the functions or time 'when' it should be triggered. The pages I've looked at seems to put these functions in not any particular order, nor do I see any "calling" routines.
I don't think there's any difference in this respect between PHP and other script languages. The "timing" ordinarily comes from where the function call is placed in the script, since PHP is executed on the server, so it is never aware of user actions in the browser.
Perhaps this is your area of confusion. PHP has completed its role and is no longer a factor, once the server sends the HTML and CSS and Javascript to the browser. The only way PHP can become aware of some user action is if a new HTTP or AJAX or cURL request is sent from the browser to the server. That's the main fundamental difference between web operations and a standalone application on a workstation.
webbiz wrote:And does someone actually have to see my code or rewrite my code to tell me how you get an email address from one page to another?
Essentially, yes! There are several ways to do that and it depends on how you want it to be handled and how to fit it in with the rest of the application.
To answer your now-specific question, there are exactly two methods for sending form data (that is, user supplied data) from a web page back to the server. You specify which method you want to use by setting the METHOD parameter in your HTML Form tag. The 2 methods are POST and GET. You can learn all these details from any tutorial on HTML forms. Having decided which method you will use, the target script will read the data from the appropriate global array variables, either $_POST or $_GET. But even before doing that, you must decide whether you want to request an entirely new HTML document or employ AJAX, which is really just using a specific Javascript object (called XMLHTTPRequest) to request that
data be returned to the browser, to be handled by a Javascript function that you define. In addition to using an HTML Form, it is also possible to send data as "GET" data using a hyperlink (HTML Anchor tag). Do you begin to see that it would be quite difficult to simply tell someone who knows no PHP how to introduce all these factors into an unseen script?
Re: Auto Send Email
Posted: Sun Mar 11, 2012 3:59 pm
by webbiz
PHP has completed its role and is no longer a factor, once the server sends the HTML and CSS and Javascript to the browser.
That statement definitely turned on a light in my head. Once the page is displayed, it's done all that its going to do...PHP-wise that is. Clearly HTML is not done yet if there is a SUBMIT button that causes some action to happen.
Well, I was hoping this would have been an easy "add this and this and you're all set" type of thing and not a redirect to having to learn all this from scratch just to solve the email issue. But it is what it is.
Thanks for explaining this to me.
All the best.
Re: Auto Send Email
Posted: Sun Mar 11, 2012 8:41 pm
by califdon
Sadly, few things are easy in web development. Yes, now you have the correct perspective. Once a page has been delivered to the browser, the server has no further connection with the browser until and unless another request is received. Such request may be a hyperlink that has been clicked, or a form that has been submitted, or an AJAX (XMLHTTPRequest) request, but absolutely any action by the user is known only to Javascript, assuming the user hasn't disabled it. This is the environment that all web development works with.
If you want to go further into web development, there are plenty of tutorials online, a few of which are actually pretty good. If you choose not to continue, I could understand that, too.
Good luck.