Creating cPanel email accounts with fopen - php

I'm using the following code to create an email account and a email forward at the same time. I'm consfused as the email forward works every time (f2) and the email creation is only working roughly half the time (f1). I'm a PHP newbie and can't understand what could cause this. Any help is appreciated!
$f = fopen ("https://$cpuser:$cppass#$cpdomain:2083/frontend/$cpskin/mail/doaddpop.html?email=$username&domain=$cpdomain&password=$password&quota=0", "r");
fclose($f);
$f2 = fopen ("https://$cpuser:$cppass#$cpdomain:2083/frontend/$cpskin/mail/doaddfwd.html?email=all&domain=$cpdomain&fwdemail=$email&fwdopt=fwd&submit=Add Forwarder", "r");
fclose($f2);

Yahoo is closing down Yahoo Mail Classic so I'm having to implement my own email. I currently use JustHost. I've made an effort to make the variables as easy to understand. If you don't understand what they mean then FIRST contact your host because (presuming you get a competent tech on the line) they'll understand what you'll need.
<?php
//exampledot.com for domain
$cpuser = 'exampled';////////////e.g. exampled, your cPanel main domain usually
$cppass = 'CPANEL-PASSWORD';/////Your cPanel password.
$cpdomain = 'exampledot.com';////The cPanel domain
$cpskin = 'justhost';////////////listed on cPanel as 'theme'
$emailname = 'john1';/////////////The username, e.g. john1#exampledot.com
$emaildomain = 'exampledot.com';////The domain name in email, #exampledot.com
$emailpass = 'EMAIL_PASSWORD';////The password for the email account
$quota = '25';///////////////////Megabytes of space, 0 for unlimited
$homepage = file_get_contents("https://$cpuser:$cppass#$cpdomain:2083/frontend/$cpskin/mail/doaddpop.html?email=$emailname&domain=$emaildomain&password=$emailpass&quota=$quota");
echo $homepage;
?>
I used just that code and then checked cPanel and the email account was created.
So your URL does work, it was just that file_get_contents function is what you want to use.

with fopen
$fopen ("http://$cp_user:$cp_pass#$cp_domain:2082/frontend/$cp_skin/mail/doaddpop.html?email=$user&domain=$e_domain&password=$e_pass"a=$e_quota", "r");
for full plugin..
1.http://tobbynews.com/create-e-mail-account-in-c-panel-using-php.html
2.http://forums.cpanel.net/f42/xmlapi-php-class-111897.html
you can ask for support in cpanel's support for assistance..

Related

piwik send email doesn't work?

my application use piwik for statistics. when I config the mail section. something wrong happen. the config is like this:
[mail]
transport = "smtp"
port = "587"
host = "smtp.qq.com"
type = "Login"
username = "username#qq.com"
password = "*********"
encryption = "tls"
and when transfer a mail the error information is like this:
An error occurred while sending 'PDF Email Report -
1.2016-11-15.2.zh-cn.pdf' to *******#qq.com. Error was 'mail from address must be same as authorization user'
and I google with this info , but nothing I found work fine.
I guess there was somewhere I can put the address from as I do before. But I don't find the place.
Could someone tell something about this question, thanks a lot.
I have handle this question. The solution is add a line in config/config.ini.php [General] code section.
noreply_email_address = username#qq.com
I don't know how it work. but obviously, it work.
Hope this solution can help someone !

cpanel email account creation issue

I am trying to create an email account via script without logging into the cpanel.
Here is the script I am using
http://www.zubrag.com/scripts/cpanel-create-email-account.php
Hosting provider is bluehost
I am getting this error
Cannot create email account. Possible reasons: "fopen" function allowed on your server, PHP is running in SAFE mode
safe mode is off in my ini file.
Here is the credential area that the script is using
// cPanel info
$cpuser = 'example.com'; // cPanel username
$cppass = 'my_cpanel_pass'; // cPanel password
$cpdomain = 'example.com'; // cPanel domain or IP
$cpskin = 'x'; // I have tried x and also bluehost here
// Default email info for new email accounts
// These will only be used if not passed via URL
$epass = 'my_cpanel_pass'; // email password
$edomain = 'example.com'; // email domain (usually same as cPanel domain above)
$equota = 20; // amount of space in megabytes
The following code is sending me the errors/warnings
$f = fopen ("http://$cpuser:$cppass#$cpdomain:2082/frontend/$cpskin/mail/doaddpop.html?email=$euser&domain=$edomain&password=$epass&quota=$equota", "r");
if (!$f) {
$msg = 'Cannot create email account. Possible reasons: "fopen" function allowed on your server, PHP is running in SAFE mode';
break;
}
The warning I'm getting is
Warning: fopen(http://...#example.com:2082/frontend/x/mail/doaddpop.html?email=asif.k&domain=example.com&password=SmallAn123!&quota=20): failed to open stream: HTTP request failed! HTTP/1.1 401 Access Denied in E:\Web Softs\wamp\www\clnt5\cpemail.php on line 81
If I print all the stuff between fopen() I get this
http://cpanel_user_name:my_cpanel_pass#example.com:2082/frontend/x/mail/doaddpop.html?email=asif.k&domain=mydomain.com&password=SmallAn123!&quota=20
I have googled a lot to fix this. Any help or an alternate script that can help me achieve this will be much appreciated.
If you have cpanel username and password then you should use cpanel API to create email accounts and for lot more functionalities too rather than these get request.
require_once 'xmlapi.php';
$xmlapi = new \xmlapi($cpanel_domain);
$xmlapi->password_auth($cpanel_username,$cpanel_password);
$xmlapi->set_port('your domain port will be here');
$api2args = array();
$result = $xmlapi->api1_query($cpanel_password, 'CustInfo', 'getemail', $api2args);
// until here you will get confirmation of your connected cpanel with cpanel api
// then create cpanel as below
$api2args = array(
'domain' => $domain,
'email' => $email_address_to_create,
'password' => $email_password,
'quota' => '2048', // quota for email you want to set
);
$result = $xmlapi->api2_query($cpanel_username, 'Email', 'addpop', $api2args);
if(isset($result->error) && $result->error!=""){
// error can be recorded here
}
else{
// email account get created
}

Collect data from email message

I want to collect data from email to mysql database using php.
If some one is sent a mail to their mail account to my mail id. I want that mail information to store in my database. for further operation. It is possible in PHP because I saw this feature in one hosting support application Kayako Fusion which developed by PHP.
So plese give some information to do this task.
If you want to parse with PHP the best way is to use a 3rd party API to revive the email and then send it to your PHP script with a HTTP Post.
I'd recommend using either sendgrid.com or mailgun.com
Both of these services will parse the email and send you the information in a http POST that you can then insert into mysql. API docs for both: MailGun Incoming Parse API / SendGrid Incoming Parse API
You can use the imap functions, for example:
<?php
$imap = imap_open("{server.example.com:143}INBOX" , 'login' , 'password');
if( $imap ) {
//Check no.of.msgs
$num = imap_num_msg($imap);
//if there is a message in your inbox
if( $num >0 ) {
//read that mail recently arrived
$the_message = imap_body($imap, $num);
//Do the stuff with $the_message
}
//close the stream
imap_close($imap);
}
You'll have to setup a cronjob (scheduled task on Windows) that connects to the Exchange or POP server, retrieve's all new emails sinds the last run and insert them into the DB.
In case of a POP mail server(I think POP will be easier), there is a comment here with all functions you need right -> here. If that doesn't work, try Googling for "PHP POP wrapper" or something similar.
In case of a Microsoft Exchange server, you'd have to use a PHP Exchange wrapper, found one here for you.
Goodluck!
You can pipe your email to a php script and then extract each part of email and store it in data base.
check this example
when you get content of email you can do what ever you want

How to send Verification/Confirmation Email when user have registered

I've written code about sending a verification mail to users who have registered !
But the thing is when i run the .php file in browser it says, not able to send the confirmation mail.
Someone told me that you need a server(domain) to send confirmation mail, it can't be sent using LOCALHOST.
Can i send confirmation mail from LOCALHOST ?? Any-way ??
If not, then tell me where can i get a FREE domain(for testing) where i can upload my .php files and send confirmation mail ??
If you're running the script from a developer server at home, you're most likely having problems with your ISP having blocked port 25.
What I would recommend you to do is use a Transactional Email service such as:
AlphaMail
PostageApp
Mandrill
Why?
Has HTTP API support (runs on port 80/443, so no ISP blocking). I.e. easy to run from home.
Future-proof. You don't have to think about hosting your own SMTP-infrastructure. Scaling it once your sendings increase.
You don't have to think about delivery. Being blocked because the IP you are sending from isn't whitelisted, the list goes on.
Statistics. Let's you track Total Sent/Clicks/Opens/Bounces.
How?
Since I am one of the developers behind AlphaMail, I of course recommend you to use it (but not only because I'm one of the developers behind it, but because it's great! :)). And since you're using PHP, it's easy to get going with the AlphaMail PHP-client:
include_once("comfirm.alphamail.client/emailservice.class.php");
$email_service = AlphaMailEmailService::create()
->setServiceUrl("http://api.amail.io/v1")
->setApiToken("YOUR-ACCOUNT-API-TOKEN-HERE");
$person = new stdClass();
$person->userId = "1234";
$person->firstName = "John";
$person->lastName = "Doe";
$person->dateOfBirth = 1975;
$response = $email_service->queue(EmailMessagePayload::create()
->setProjectId(12345) // Your AlphaMail project (determines template, options, etc)
->setSender(new EmailContact("Sender Company Name", "from#example.com"))
->setReceiver(new EmailContact("Joe Doe", "to#example.org"))
->setBodyObject($person) // Any serializable object
);
Another great thing with AlphaMail is that it separates logic from design. So you never have to bloat your code with ugly non-standard (email) HTML again. And once you need to change things it's no digging in code, just log into the AlphaMail Dashboard and edit your template immediately. Also, the templates are built using the simple template language Comlang, so they are highly personalizable.
<html>
<body>
<b>Name:</b> <# payload.firstName " " payload.lastName #><br>
<b>Date of Birth:</b> <# payload.dateOfBirth #><br>
<# if (payload.userId != null) { #>
Sign Up Free!
<# } else { #>
Sign In
<# } #>
</body>
</html>
You can use sendmail , smtp or some other services like Amazon SES . Amazon Simple email service provides sandbox feature with free of cost (but you need credit card to use its service) and it can easily configured into your localhost.

Zend Framework: Some email users get errors when trying to open PDF attachments?

I'm having a strange problem and not sure how to troubleshoot it. I have created a script in one of my Zend Framework controllers that allows an administrator to log in, upload a PDF, and send as an attachment to everyone subscribed to the mailing list. The problem is that some users report that they are unable to open the PDF attachment, that the file is corrupt. I think this is only happening to AOL users, but I'm not positive. Have you encountered this problem before? Or maybe it is not a problem with AOL, but something wrong with my code?
Here's the code that does the work:
Also, I'm using ZF version 1.6.0. Not sure if that is relevant.
//assuming the form is valid:
$table = new Subscribers();
$rowset = $table->fetchAll();
foreach ($rowset as $row) {
$mail = new Zend_Mail();
$mail->setBodyText($form->getElement('body')->getValue())
->setFrom('weekly-update#email.com', 'Weekly Update')
->addTo($row->email)
->setSubject($form->getElement('subject')->getValue());
$fileLocation = $form->getElement('attachment')->getValue();
$fileContents = file_get_contents($fileLocation);
$attachment = $mail->createAttachment($fileContents);
$attachment->filename = str_replace(Zend_Registry::get('config')->downloadsLocation . '/', '', $fileLocation);
$mail->send();
}
It appears (to me) that in this line of code:
$attachment = $mail->createAttachment($fileContents);
you likely need to add the additional header information available in the createAttachment method of the Zend_Mail framework::
$attachment = $mail->createAttachment($fileContents,
Zend_Mime::DISPOSITION_INLINE);
Many larger email providers are sticklers for strict adherence to good email policy (I've found).
Play around with this and I'm sure you'll get it to work.
I also had this problem.
I'd suggest you trace out the file stream info somehow. The issue with my app was that the $fileContents = file_get_contents($fileLocation); call wasn't getting the stream of the file properly, so this is where you might be falling down.
Try this:
$mail = new Zend_Mail();
...
var_dump($mail->send());
You should see a bunch of gibberish where the file stream comes out in the var_dump under the key:
["_content:protected"]=>
string(37129) "%PDF-1.5
etc...

Categories