How can I change password of the mail account using php. I am using IMAP functions.
IMAP doc : http://php.net/manual/en/book.imap.php
Note: There is no acess to cpanel API
If you don't have access to the cPanel API, then you're even less likely to have root access to the various files that would be needed to make the changes.
Changing passwords is not a feature of IMAP, POP or SMTP - it's a server configuration issue, so you need to manipulate the server configuration. Several hosts provide APIs (such as cPanel / Hostgator) but you've ruled that out, so he only other option would be "exec", and I wouldn't touch that with a bargepole for cPanel, Plesk or simlar as you'd also need ot manuliplate the databases that store the configs. Ouch, if if you had root access.
Edit: A bit more reasearch and I have found this: http://trac.roundcube.net/browser/github/plugins/password/password.php that supports several back ends. However the cPanel option uses the cPanel API; so still no luck!
What you could try is mailpw_change. It is not really PHP, but a simple HTML UI with a Python script that is called underneath (which you could adapt to your needs as it's super-simple).
Related
I am hosting my website on https://www.gandi.net/en , thing is they don't allow connections over ssh only sftp.
I have a form on my website and want to allow user to contact me through that form. In other words an e-mail needs to be sent from form#mydomain.com to me#mydomain.com.
In order to do that there are a couple of options I tried, but none of them seems to work:
1) PHP's mail function: doesn't support authentification. In order to send an e-mail from form#mydomain.com I need to authenticate. And that doesn't seem to be possible with the mail-function
2) PHPMailer: I saw many people recommending this solution. I downloaded their sources and had a look. It seems like in order for it to work you need to actually install PHPMailer using composer. I can't run composer via sftp...
What other solutions exist? Or what workaround exists?
Thanks!
2) PHPMailer: I saw many people recommending this solution. I
downloaded their sources and had a look. It seems like in order for it
to work you need to actually install PHPMailer using composer. I can't
run composer via sftp...
You don't need to run composer, just download the PHPMailer files manually and upload it via sftp. Composer just makes it easier to install packages, the PHPMailer itself existed long before Composer was a thing.
If you don't know how to install it without Composer, take a look at this answer.
You can give swiftmailer a try: https://swiftmailer.symfony.com/
It is used by Yii2 Framework as well.
If I am not mistaken, for most if not all PHP extensions, you can integrate it into your website by using composer from your own development machine, and then you'd upload the source using FTP. You don't need to use composer on the host server.
I have used swiftmailer with Yii2 websites on a public host and I didn't have to do any special setup on the host.
If all else fails, change host. Get a refund and use your new host's web transfer services to move with minimum effort.
Looks like if you use a SPF TXT record in your DNS setup for their Simple Hosting package, you should be able to use mail() as-is without having to authenticate to your mail host:
# 10800 IN TXT "v=spf1 ip4:217.70.176.0/21 ip6:2001:4b98:c::/48 ip4:217.70.185.10 ip4:173.246.97.150 ip4:217.70.186.165 ptr ?all"
Source:
http://wiki.gandi.net/en/dns/zone/spf-record
Which has this quote:
This Simple Hosting records is only used if you plan to send e-mails through your website (via contact form, etc..)
After you've submitted each of these changes, be sure to activate the new version of your zone file, and keep in mind that it will take about 3 hours for it to take full effect due to the standard DNS propagation delay.
You can confirm the SPF TXT record is deployed using various online SPF testing tools.
Since a lot of users have the ability to edit StackOverflow posts, I recommend going to the source and copying and pasting the appropriate SPF record directly to avoid shenanigans. Also the Gandi Wiki will always have the latest list of IPs whereas this post may go stale after 6 months.
I recommend Composer-less CubicleSoft Ultimate E-mail Toolkit or one of the other already mentioned libraries over directly using the built-in PHP mail() function. The PHP mail() function is very misleading. It simply drops a properly prepared mail message into the mail queue on the local host. However, e-mail is very complex and really needs a library even for the most basic PHP mail() use-cases.
If you want to use one of the other Composer-enabled libraries but don't want to upload thousands of little rinky-dink files that comes with Composer-enabled software, then check out CubicleSoft Decomposer. Decomposer takes an entire Composer project tree and generates standalone builds with 1-2 files as the output.
I have cPanel servers which run the same script, but I've hard coded the server name in to the code as I can't find anywhere to grab the actual server domain.
Imagine 3 cPanel servers and these are the server domains:
apple.hosting.com
banana.hosting.com
carrot.hosting.com
While running a PHP script to send mail via SMTP, I need to connect to the server and want to use the server name that would be provided for secure connections.
I don't want to create an array of the IP addresses and then have it compare, as that won't work with dedicated IP addresses.
I tried ini_get('SMTP'), which just returns a useless 'localhost'.
I tried ini_get_all(null,false), and no joy.
I checked the $_SERVER global, but only the domain being accessed appeared.
The only thing that returned the server name was phpinfo().
It took a while to find this, and in composing the question, I found the answer. Rather than waste what I think is a good question (since I couldn't find the answer easily), here it is:
New as of PHP 5.3:
gethostname();
That's it, nice and sweet.
Read more here: PHP function gethostname
You could send yourself an email an look in the email header (In Outlook: Open the mail, View->Options, there is 'Internet headers)
The normal sub-domain is mail.domain.com, and another solution could be:
Follow this:
cpanel --> go to your mailing accounts -- > click on configure mail account -- > there somewhere in the page you will get the information about your smtp server
And on that page you should find the information.
Have a look at mxtoolbox
Other then that, you'll probably want to check stream-socket-client
I want to know how to create subdomain using PHP.
The server uses cPanel control panel and i have seen code but not clear of what it does.
Is there any php function to create subdomains?
Or do we have to rely the server settings for this?
if you have cPanel then you can use what i used.
very simple function provided my hosting company server guy.
http://vikku.info/programming/php/create-subdomain-dynamically-in-php-code-to-create-subdomains-in-server-using-php.htm
As the other use said i agree that php cannot do anything with this...
These functions call cPanel libraries indirectly and those functions can access server level functions because they will have permission to do that.
PHP has nothing to do with domain or subdomains. You have to configure your server application accordingly to achieve this.
If you are using apache, take a look in their documentation about vhosts.
how do i go about adding ftp users to an apache web server? i need the user to register from normal web/script and then have an FTP account set up for them automatically.
I have seen the cPanel API, and it is pretty decent, but since cPanel costs money, i don't wish to use it for this project. I'm also reluctant to use any other lisenced piece of software.
i want to be able to do it using shell/batch (or pure PHP, though that hardly seem plausible)
Well as you said Apache is a Web and not an FTP Server. But most FTP servers like e.g. PureFtpd offer MySQL authentication. So you just have to modify the authentication table with PHP to add new users.
We have a website that emails the contents of a contact form to our client. We would like to change this to make it a bit more secure (sensitive data can be sent over the contact form), we have encrypted the page with an SSL certificate so the only weak link we have at the moment is the email.
We already have an SSH connection setup to our client's servers and I was wondering if anyone knows if it is possible to send an email (possibly with attachments) over that connection?
Our web server is a linux machine and we are able to install applications ourselves. The client's server is a unix server, however their email system is Microsoft Exchange.
We've discussed PGP and it is not an option for our client, they will not install it on their systems.
Thanks for any help.
Peter
To make my answer clearer I see three (3) systems here.
The webserver running the PHP script; later refered as the WebServer
The Unix server running on your client site; later refered to as the UnixServer
The Exchange server running on your client site; later refered to as the ExchangeServer
What you could do is use autossh to tunnel a connection from the WebServer through the UnixServer server with an endpoint at ExchangeServer. It is no end-to-end encrypton since you would not have an encrypted link from the UnixServer to the ExchangeServer it gets you closer to your goal.
Full documentation on autossh can be found here
The basic steps for the setup would be this:
A. Setup passwordless authentication from the WebServer to the UnixServer. You'll have to be carefull to protect the RSA key generated otherwise you've just opened a gaping hole on their system. Ideally run autossh under an unprivilege user and have the account used on the UnixServer to be unprivileged as well. Make sure you test the connection before you start using autossh
B. Setup your ssh options for keepalive (autossh is a fallback option). Make sure that the ~/.ssh/config file for the user launching autossh has these option setup:
TCPKeepAlive yes
ClientAliveInterval 60
ServerAliveInterval 15
ServerAliveCountMax 3
C. Setup autossh. Linux.com as an articile about it here and debianadmin.com as one here.
If the client's server is configured so the "mail" command works you ought to be able to use that. And it is easy to test: ssh in and try it.
Otherwise, you probably want to go with smtp over SSL with encryption direct to their mail server.
I'd be inclined to store the information securely on the server, and email a notification to the user who then can login and see this request (and all other recent ones?) in the web page.
You don't have to mess around with trying to make email secure and working with systems that aren't in your domain of expertise, you can secure your PHP app properly, and take advantage of security features already easily available in browsers.
ssh -L $LOCAL_LISTEN_PORT:$EXCHANGE_SERVER_IP:25 username#sshdserver
http://www.ssh.com/support/documentation/online/ssh/adminguide/32/Port_Forwarding.html