I want to send a welcome email when a user registers in my app.
When a user registers he gets redirected to his profile page.
I tried sending email while user creation but the email() takes 7 seconds to send email, and the page waits till then and then redirects the user to profile after 7 sec.
This is not desired. I want to redirect user as soon he registers, and send an email along the process. It takes 7 sec don't know why. i tried it online on godaddy and hostgator account as well as on my localhost.
BTW: i am using PHPMailer to send email.
How can can i make a standalone process which on invoke calls my sendMail.php with email $_POST[] parameters {to, subject, body}.
i though ajax call will do the trick, but as soon as my page redirects from registration to profile, the email script stops.
I tried this code:
<script language="JavaScript">
$.post( "sendMail.php", { to: "$to", subject: "$subject", htmlBody: "$htmlBody", altBody: "$altBody" } );
location.href=profile.html
</script>
Please help, i searched a lot but they work on shell which i am not, and other solutions were unix/linux based. i want to make it work on xampp as well as godaddy linux shared hosting, with NO ssh access.
You could use Mail_Queue, which is a job queue specifically for sending emails, or utilise Zend_Queue [ZF1, ZF2] to write something customised to work with PHPMailer. You might even consider using Gearman.
You could try to put the javascript in your profile page so it runs once they hit the profile page and not on the form submit. Just need to check if the welcome email has been sent already in you sendMail.php script.
But using this script to send an email may not a very good idea as it could enable a malicious user to send an email with what ever content they wanted to whoever they wanted and if it was marked as spam then it would be your server that got blocked. It is a very common technique used by "spammers".
You would have to be very careful in how you handeled the email before it was sent so as not to breach your agreement with your hosting company.
Php is single threading language. This means that you can not start a job before previus one executed (and finished)...
You may change task order. I mean you may send the email, after welcome page completely rendered.
Try with this order;
1) register user
2) show welcome page,
3) send welcome email....
with this order, your new user will not wait for 7 seconds before see welcome page.
Related
I want to build a system where the user can just reply to the email he gets. What it needs to do is: once the user replies to the email, that email does not go to any user, it will execute a url with GET parameters that triggers a script that updates the database and send another user an email.
Let me explain again:
User A gets into the system to insert his message, his message will send a notification to User B, user B replies to it, but instead of sending to User A, it will Update a database and notify User A saying that User B has sent a message.
the main point is that User A and B does not communicate with each other directly, only allowing them to communicate using the system.
I need to use PHP.
If someone can help or point me into the right direction I will appreciate it!!
Thank you all!!!
If you have access to the system users, you could pipe within the .forward file to a php script.
Or run a php script via cron/wget that logs into that email account and processes emails.
You need a email server, which will be receive and sent messages.
And just read new emails with PHP and do another magic that you want with PHP IMAP functions.
This is some type of funny question to ask here.
Well, I am using WordPress with registration. When a user signup. Wordpress send email containing user name and password to login.
I simply want that email to receive after delay of 10 minutes. Is there is something to do with server config OR with WP.
Any clues?
You would have to have multiple things to have it work, you will need to have access to cron in order to delay the job and you need to be able have enough knowledge to edit WordPress to stop the function from sending the email. If you can schedule the job to run a command with the parameters for the email in it 10 minutes later the rest should run on its own.
I have a page which handles form input. It does a few things, sends a few emails, and redirects the client to another page. Things work well.
The issue I that sending email is slow, and if I have to send a couple emails, the response time is unacceptable. I would like to redirect the client to the result page, and then send the emails. Unfortunately, the redirect() call in CodeIgniter ends execution.
Is there a way to do a 302 redirect and allow the execution of the script to continue?
It is important that the 302 redirect headers get flushed out. It would be OK, but is not required, that the connection be closed. What is important that the user gets redirected before the emails get sent, in order to not have to wait for the email sending to finish.
I think using a message queue would be more appropriate than having a possible zombie process sitting there. Essentially when this action is taken dump a job into a job queue with the body of the e-mail, who it's going to, the subject etc. Then have a cron job set up to read this queue every two minutes, say, and send out the e-mail.
You can also look into using something like the Simple Queue Service from Amazon (http://aws.amazon.com/sqs/faqs/#What_can_I_do_with_Amazon_SQS) along with the Simple E-Mail Service to create a scaleable solution.
On my site, I have a feature that allows you to follow the updates of other users. When a user makes a change to their info, anyone following him or her will be emailed of this change.
I have it set up so that the php changes the info in the database, then searches through the users contacts to see who is following him/her, and sends emails to those who are following notifying them of the change.
The problem I have run into since adding this notification feature, is that insead of the page loading (form posts to itself) and showing the change almost instantly, (depending on how many people are following a particular user) it can take a few munites for the page to load and show the update (because the php is sending all the emails before the page reloads).
How can I set it up, where the script to send the emails, is run somewhere in the background, and the user does not have to wait for the emails to send before the page reloads, and could possibly even exit out of the website and still have the emails send if still the script is still running?
P.S. All my programming and development skills have been self taught, so I don't know a lot of terminology..... You may have to dumb down your responses so that I will understand what you are talking about. Sorry for the inconvenience, and thank you very much for any help.
I'm surprised it takes several minutes just to send some emails, but anyway you can do this in at least four ways:
Use ajax to send the form data to a separate script that sends the emails while the form posts normally
Have the form script fork (pcntl required)
Make an asynchronous request to your own page via php (either set a low timeout with cURL, or open a socket)
Use exec('script-that-sends-emails args >> some-other-file 2>&1 &');
I need a php script that you can use to set up a online newsletter and then have a link that will allow the visitors to email the Web Page as a Newsletter to someone elses email...
Is this possible? I suppose it is, as it is done here. That is exactly what I need. I want to set up a newsletter, add a script that will allow the visitor to send that newsletter directly to a friends inbox. http://www.pretoria.co.za/interactive/forward-newsletter.html
I suppose I just need the script to send an html file to the email address
Please help - thank you
Use a MySQL and mail function, or use e.g. this.
That can be written fairly easily using one of the email wrapper scripts, such as phpMailer. However, when doing so, pay particular attention to issues that could lead to spam and other abuse of the form. You should spend the time to really lock down the client-side, as well as server-side validation on all input variables.
That being said, the best way is to save the HTML of the page in a database, and pull it out into the body of the email. You should also include a text-only version as an alternate body so people without HTML email will be able to read it. Then, when someone submits the form, just validate the data, put together the message with the methods available with the mailer class you choose, send the email, and then redirect to a "thank you" page.