I would like to know how to setup a system in php that I could send emails to and the email content would poblish on my blog as a new post and the email subject would be the new post title.
Am not using word press or any of those blogging platforms am running my own blogging script and a php 5.x version.
I don't even know how to get started on this kind of programming challenge please any one with any ideas is welcomed.
Joe
You would need to create a script that is able to read from your email account. Php has the IMAP library that enables you to read email messages. Check this link to see how you could use the library.
You would need to schedule the script to be run at a periodic interval of time (eg. every 5 minutes). In Linux you would setup a cron job to do it.
So, I mean the script should be invoked periodically. If it finds a new message, it would then update your blog by taking the body of the email.
you need to set up a database that has all the tables and rows necessary to hold all the vital information about the post that people will send via email. then using MYSQL in your PHP file you need to connect to the database (host, username, and password) and then create your own query to enter the desired data to the database.
Related
I am trying to set up a system where a user enters some information in a form and an email will be constructed where the information is saved into mysql.
I am trying to figure out how to make it so the email will be sent, for example, 20 minutes after the user makes their input. (Without the user staying on the browser).
I need this delay as I need the ability for an admin to log on to a page to look at the email and possibly edit it before it sends.
Is this possible through a cron job. Am I able to set one up that automatically checks sql table for an update and then sends the email after a certain time?
Or is it possible to delay a php script with the sleep function and then send the email. Can I make the PHP script still run when user has closed site and left?
you can use mySQL to store the data sent by the user. this data will be accessed later using another script triggered by a cron Job: if you have the ability to set cron jobs in the control panel or via access to the server, go ahead, use cron tab syntax to define when the job will be triggered, this website may help you:
https://crontab-generator.org/
another approach is to use external service to trigger an event every interval, the event could be accessing the cron job script via HTTP.
if you want your email to be sent exactly after 20 mins, please add a field to your mysql table indicating the desired send date(beware of timezones).
you may also want to add a flag indicating if the email is sent, so you do not send the same email twice.
You can't (easily) have a PHP script stay alive that long.
Your best strategy, IMO, would be to have the PHP script create the email file, and notify the human.
Then you can have PHP run a shell script which uses the "at" program to schedule a task to happen in 20 minutes. At is a cousin of cron, but is better suited for this job.
That scheduled task will be to take the e-mail message, move it some place else (like a "done" directory), and pipe it through your mailer. tip: /usr/sbin/sendmail -t < myEmailFile will work on most Linux boxen.
I am using php and Mysql.
I have a record in my database and i want to check status value of the record after 24hrs of its insertion if it is still in pending or no changed i want to send an SMS and an Email to some person relevant to the status.
To achieve this i have implemented a solution in which i used a php code but it need to continuously execute and check status of record that may cause DoS.
In Another solution i create a trigger but i can't able to send db values as parameter to the php file.
so what should be its solution????
Two ways came into my mind for this.
First, (the good way) using cronjob. It's a really good way.
Second, (bad way for your purpose) Check to see which rows has age of 30 days in each request coming to website. There are cons for this way as the website doesn't get visitors for some days then SMS or Emails won't be sent on time. Another bad thing is it executes on every request so loading time and memory will be consumed during this process.
created a php file which contains a functionality of send sms and email.
then create cronjob:
wget http://example.com/x.php
provide full address of your file.
while creating cronjob set time interval 24hrs
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 am trying to work out how to do something. It must be possible - I've seen something similar done in multiple systems (Twitter, facebook etc.)
The basic thing I want to do is - someone leaves a comment on my website. The comment goes to my email, as well as to my MySql database. I then reply directly on my email. The reply is saved to the database, and auto-approves the user's comment.
I can't work out how to speak to my MySql / PHP system directly from an email. Also - I can't work out how to set up the inboxes?
I am guessing that I'd need to set up mailserver rules so that emails sent to xxxx-response#mydomain.com are actually redirected to a php script, where xxxx is an identifier of the original comment?
Thanks for any light that you can shed...
Assuming you're on a unix system, you could set up an account for receiving the mail, e.g. "fred", and use a .forward in fred's home directory to pipe emails to your php script. e.g.
.forward:
|"/usr/bin/php /path/to/your/script.php"
which will invoke your script anytime an email arrives in fred's mailbox.
You can't 'talk to mysql from an email'. An email is a passive piece of text, nothing that can take actions.
The solution is based on something like this:
You have an email account and poll that accounts Inbox by a php script in a periodical manner, by using wget or similar in combinition with a crontab entry. You can also create an event driven approach, but that is more complex and does not really offer advantages. For all messages found inside that inbox you check if it matches any previous entry in the database. You can do that since you have access to the messages headers and body (the text) by php. That is all you need. Typically the connection between two messages is done by evaluating the 'In-reply-to' header that is set by email programs when you press the reply button. It is like a reference.
The access to the accounts inbox is done by standard mail access protocols, typically pop3 or better imap4. When the mail server is not on the same system then abviously you want to add ssl encryption too. php's imap extension is a very good start for implementing such a client, it supports several protocols.
I am currently working on a registration based website, and I have the server sending an activation email to the user upon registration. This is all done in PHP so, as you can imagine, I am using the mail() function.
This is all fine and dandy, once the user gets the email and clicks the activation link, the 'active' field that is in the 'Users' table is set to true. Here's the problem though, in the case that a user does not confirm their email address, what am I to do?
I have thought of holding details like the date and time the user registers but I don't know how to proceed with this data. How do I have the server automatically delete the user from the database after a set amount of time?
That's what I think I should be asking, but in all honesty I don't know the usual protocol...
Conclusion: Since Cron is for Unix based servers I've had to pass on it, but I found it very interesting that I could just use the Windows Task Scheduler that is built into Windows. This at least means I can test it on my PC before any server hosting. Thank you all
You should definitely store the date and time that the activation link was sent.
There isn't really a way to tell the server to automatically delete stale user data, but it's easy enough to code up yourself. Assuming you have access to cron on your server, you can set up a cronjob to run (for example) every night at 2am and execute a PHP script that searches the database for users who were sent a link more than X days ago but never confirmed it
i think the solution would be Storing the timestamp while sending the mail.
now run a cron every 15minutes which would check that which values are having timestamp more than 24hrs or any timelimit you want and then delete it from db
Just call in your index.php file the following code. (Why index.php ? - because it is requested every time and can "act" as a cronjob.)
(Just Pseudo Code - might need some tweaks!)
mysql_query("DELETE FROM user WHERE active = 'false' AND registerTime < (NOW-60*60*24*7)")
This will delete all Users which have not been activated within 7 Days.
It's just a concept idea i think you can build on.
You should look into cronjobs that you run daily. Simply put in a field in your database with the time your user registered.