Log in

View Full Version : php mail function in ubuntu



hemi519
11-20-2010, 09:19 AM
Hi All,

I was using mail function in windows it was working fine with the code i wrote. Now i shifted to UBUNTU. But that code is not able to send mail here.I installed sendmail but there is no result. here is errors it is giving in /var/www/root when i tried to send mail



From root@xxxxx-desktop Sat Nov 20 14:36:02 2010
Return-Path: <root@xxxxx-desktop>
Received: from xxxxx-desktop (localhost [127.0.0.1])
by xxxxx (8.14.3/8.14.3/Debian-9.1ubuntu1) with ESMTP id oAK961mF010585
for <root@xxxxx-desktop>; Sat, 20 Nov 2010 14:36:01 +0530
Received: (from root@localhost)
by xxxxx-desktop (8.14.3/8.14.3/Submit) id oAK961Yf010475
for root; Sat, 20 Nov 2010 14:36:01 +0530
Date: Sat, 20 Nov 2010 14:36:01 +0530
Message-Id: <201011200906.oAK961Yf010475@xxxxx-desktop>
From: root@xxxxx-desktop (Cron Daemon)
To: root@xxxxx-desktop
Subject: Cron <root@xxxxx-desktop> [ -d /usr/share/dtc/admin ] && cd /usr/share/dtc/admin && /usr/bin/php /usr/share/dtc/admin/stat_total_active_prods.php 2>&1 >> /var/log/dtc.log
Content-Type: text/plain; charset=ANSI_X3.4-1968
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>

PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/mcrypt.ini on line 1 in Unknown on line 0
PHP Warning: require(../shared/mysql_config.php): failed to open stream: No such file or directory in /usr/share/dtc/shared/autoSQLconfig.php on line 109
PHP Fatal error: require(): Failed opening required '../shared/mysql_config.php' (include_path='.:/usr/share/php:/usr/share/pear') in /usr/share/dtc/shared/autoSQLconfig.php on line 109




this is my code from PHP mail

Iam getting all the values for DB.

$To =$var['email'];


$Subject = "EDIT YOUR POST";


$Reply = "$var[email]";





$From= "abc.com";


$Body="";



if(mail($To,$Subject,$Body,"From:$From\r\nReply-to: $From\r\nContent-type: text/html; charset=us-ascii"))
{

echo"message is sent";
header("Location:reg.php");
exit();
}

When i submit my form page is displaying "Message is sent" but no redirecting to reg.php or no mail is thr in my gmail

bluewalrus
11-20-2010, 04:04 PM
Do you know what these errors are? I'm assuming you also have switched from PHP4 on windows TO PHP5 on ubuntu. Going from 4 to 5 should be fine but if you plan to go back at some point it could be tricky.

On to the errors for the first one


PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/mcrypt.ini on line 1 in Unknown on line 0


use

//single line comment
or

/* multi line comment*/
To the error messages...

PHP Warning: require(../shared/mysql_config.php): failed to open stream: No such file or directory in /usr/share/dtc/shared/autoSQLconfig.php on line 109

Check your file location and permissions.


PHP Fatal error: require(): Failed opening required '../shared/mysql_config.php' (include_path='.:/usr/share/php:/usr/share/pear') in /usr/share/dtc/shared/autoSQLconfig.php on line 109
Are you requiring the same code twice? This isn't necessary because it will already be present after the first require.

If you are using any values in the config file this could be the reason for it not sending.

traq
11-20-2010, 08:58 PM
are you using normal ubuntu or the server edition?

the desktop/netbook versions have lots of file permissions restrictions (basically everything outside of your home/ folder is going to be untouchable by default). If you don't know much about chmod and terminal commands (etc.), be careful so you don't mix anything up.

hemi519
11-22-2010, 04:47 AM
Iam using desktop edition

traq
11-22-2010, 05:47 AM
lampp or did you install everything separately?

I'm assuming it's the reg.php that is encountering the require() error; and you aren't seeing the page because the script dies there. I wouldn't know for sure, however, without seeing your code.

(BTW, you're getting the error twice because the first time is a warning, and the second is the fatal error. And is there a reason you're using "../shared/" when you're already in the shared/ directory?)

Are you sure the file /usr/share/dtc/shared/mysql_config.php exists? If so, double-check the file permissions.


As for the localhost not actually sending mail, that could be for any number of reasons, and I don't think I'd be qualified to sort them out.

hemi519
11-22-2010, 05:52 AM
No there is no file with mysql_config.php in the shared folder. Should i manually create or is thr any other way to get it

When i tried to create mysql_config.php manually and tried to run the script once again. It gave me this error

PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/mcrypt.ini on line 1 in Unknown on line 0
PHP Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: NO) in /usr/share/dtc/shared/autoSQLconfig.php on line 22

traq
11-22-2010, 08:48 PM
If you have PHP scripts that use the hash sign ( # ) for comments, it's probably a pretty old script.

You should not simply create a file named "mysql_config.php" - that would solve the require() error, but I would assume that that file is supposed to contain database configuration settings, so it will cause other problems if you don't know what they're supposed to be.

You're being denied access to your database, so I would assume that mysql_config.php holds (at least) the connection info and credentials ("root@localhost" with no password is the default options for mysql_connect()).