I am working on a PHP project that uses PHP's built in mail function. I am adding the option to use Pear mail.
It seems that in most hosting environments, using:
require_once('Mail.php')
doesn't work which is what all of the examples I could find show. Writing the include path as:
require_once('/path/to/pear/Mail.php')
also doesn't seem to work. However, setting the include path like:
set_include_path('/path/to/pear/')
require_once('Mail.php')
does work. Because there is a configuration file in my app where this is stored and the config is used in most of my pages (not having to do with email), I am not sure if this is a good idea. My config file now has the values stored like this:
// pear smtp mail settings
set_include_path('/path/to/pear/');
define('PEAR_INCLUDE_PATH', 'Mail.php');
define('SMTP_HOST', 'ssl://smtp.gmail.com');
define('SMTP_PORT', '465');
define('SMTP_USER', 'username#gmail.com');
define('SMTP_PASS', 'password');
Is this going to create problems for me? How should I do this?
Thank you
Your pear include path should be set globally in your php.ini file -- if not, you have a broken pear/php installation.
But if you want to be extra-paranoid, you could ship a local copy of pear's Mail and Net_SMTP modules.
Related
I understand that I can set the option on any specific instance, however what I would really like is to set something up php.ini or somewhere similar which will handle this across all projects and all instances.
Does anyone know a way for me to accomplish this?
EDIT:
I am particularly interested in a solution which will allow for the certificates to be in different locations on different servers.
I am developing on a Windows machine which needs this but deploying to a Linux server which not only doesn't need it but doesn't even have the path indicated.
I understand that I can use conditions to check where the code is running but would prefer to just have it work out of the box. It seems to me that this is really an issue for curl and PHP to handle rather than my code and hence the settings for it belong there.
I found the answer here (in the user notes): http://php.net/manual/en/function.curl-setopt.php
Just add this to you .ini (note: you cannot use ini_set, although I don't know why you would want to. Thanks #Carlton):
curl.cainfo=c:\php\cacert.pem
And get that file from: http://curl.haxx.se/docs/caextract.html
Works and you aren't opening yourself up for MITM attacks
Here is a patch to 'emulate' what we can see on linux when a valid crt data has been found at build time (which is the case for almost all distros):
http://www.php.net/~pierre/patches/curl_cacert_default.txt
it adds a (system) ini settings to define the path to the cacert, curl.cainfo=c:\curl\ca.crt
cacert data can be fetched here: http://curl.haxx.se/docs/caextract.html
DLL for php 5.3 can be found here: http://www.php.net/~pierre/test/curl-5.3-vc9-x86-ts-nts-cainfodefault.zip
DLL for php 5.2 can be found here: http://www.php.net/~pierre/test/curl-5.2-cainfodefault.zip
Please let me know how it works.
download cacert.pem add to folder php
copy url the place of file cacert.pem
[curl] curl.cainfo="C:/xampp/php/cacert.pem"
#Matt is right, but I would add that curl.cainfo is a PHP_INI_SYSTEM directive so you must set it in php.ini...using the ini_set function in a script will always return false as I found out after too many minutes of head banging
You could create a wrapper function which sets the option and use php.ini's auto_prepend_file to load the file it's defined in, but your code would have to be changed to use this wrapper function instead.
Example:
function my_curl_init($url=null) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CAINFO, getcwd().'/cert/ca.crt');
return $ch;
}
I am trying to create email account in cpanel using php like test#mydomain.com. I tried cpanel api's , xml api etc.
fopen ("http://$cpuser:$cppass#$cpdomain:2083/frontend/$cpskin/mail/doaddpop.html?email=$euser&domain=$edomain&password=$epass"a=$equota", "r");
this gives me error "Cannot create email account. Possible reasons: "fopen" function allowed on your server, PHP is running in SAFE mode"
but not worked any more. can any one tell me what is the problem exactly, is there any settings I have to set up in server or any thing else.
thank you in advance :)
As the error suggests probably you have allow_url_fopen on the disabled_functions list on your php.ini (default location would be /usr/lib/php.ini).
Alternatively you can use the perl script provided by cPanel to create an email address from command line:
/scripts/addpop user#domain.com password quota#
Example:
/scripts/addpop contact#abc.com password 1024 (this will create the email address contact#abc.com with the password 'password' and with 1024M (1G) as quota
If you do want to use that in a php script then use the php shell_exec() function to execute the command above and you're good to go.
I would advise against enabling allow_url_fopen in php.ini long termn and leave it like that since it might pose security risks to your server.
I have a Windows 2003 server with PHP 5.24 installed on it.
I have read several posts (including the PHP manual page) on the Internet that say that sendmail_path in php.ini can be set to use a program such as Fake Sendmail which has the ability to push the mail file to my MDaemon pickup directory. I have downloaded that program and attempted to use it.
The problem is that sendmail.exe never gets executed.
sendmail_path = c:\SendMail\sendmail.exe
To verify it, I setup a simple batch file that writes to test.log when executed and changed the sendmail_path to point to the batch file. I verified the batch file does indeed create my test file when run from the command line, but when I try to send mail, the file does not get created.
sendmail_path = c:\SendMail\test.bat
The batch file never gets called.
I have tried a number of different things such as creating sendmail.exe in a path of /usr/lib/sendmail in both the c: root as well as the PHP programs folder but cannot seem to force PHP to use my file.
I have also tried putting the path name in single and double quotes, but nothing works.
In my PHP mail test I get get a fail msg and my PHP logfile shows the mail attempt to be delivered, so I know the mail process is being called.
Looking for some suggestions as to what to try next.
Gave up on trying to redirect PHP mail and just configured my servers SMTP settings to accept it. Although I had wanted to have my MDaemon mail server handle the workload, this method will suffice for the limited use it will get.
You have syntax error in php.ini! Just copy php.ini-development to php.ini and set:
SMTP =
sendmail_from =
sendmail_path = "c:\SendMail\sendmail.exe -t"
Or fix error in php.ini. Enjoy
I'm trying to set up a php script to send an email on a server with a joomla installed, I got the some script working in other project and is working fine.
I'm using this script on a landing page separate from Joomla. I had check the phpinfo and this is what it's show.
mail.add_x_header On On
mail.force_extra_parameters no value no value
mail.log no value no value
sendmail_from no value no value
sendmail_path no value no value
I'm wondering if the joomla is interfering with the mail function of php or if the function is not properly set up in php.ini
Thank you!
I am sure there are lot of plugins you can install.
Or,
Try PHPMailer. I have used it in the past. It's very easy to implement.
https://github.com/PHPMailer/PHPMailer
Hope this helps.
It means you haven't correctly setup your mail server in Joomla!
To setup the mail server go to Global Configurations > Server > Mail settings
Choose the best option for your mail settings from the dropdown and setup!
If you have a cPanel, go to Mail section and find info about your email, authentication type and more!
Hope this helps!
The problem:
My /min/ files are in different places for my local and live server:
localhost/min/
/mnt/foo/bar/hello/example.com/web/content/min/ (from $_SERVER['DOCUMENT_ROOT'])
Min works fine on my localhost but after uploading the same files via ftp to my live server I get a 400 bad request error. This is clearly due the different document roots.
What I've tried:
Changing the $min_documentRoot = '' variable in config.php file to
$min_documentRoot = '/mnt/foo/bar/hello/example.com/web/content/'
Still gives the same errors.
Additional info:
My requests look like this:
src="/min/b=js&f=jquery.min.js,bootstrap.min.js,site.js"
What am I doing wrong?
how are you minifying? is it with zip?
make sure that the live and local servers both have the same setup. especially, make sure that they both have the required minification functions available to them. for example, the Zip PHP functions are not installed by default in Fedora installations.
check the online server's httpd error log