Re: Problem sending mail

From: Date: Mon, 30 Aug 2004 22:03:26 +0000
Subject: Re: Problem sending mail
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-195215@lists.php.net to get a copy of this message
Zoran Lorkovic wrote:
$file = file_get_contents("text.inc");
    $start = "[start]";     $end = "[/end]";     $pos_start = strpos ($file, $start);     $pos_end = strpos ($file, $end);     $data = substr ($file, $pos_start, $pos_end);     mail ("myemail@domain.com", "My Subject", $data); 
This code works when I call it from browser, but when I call it from command line, $data is not put into mail (mail is send but it is empty, without any data in body). File text.inc looks like this: [start]some_text_goes_here[/end] [other_start]other_text_goes_here[/other_end] Regards. that would depend from which place you run the script.
file_get_contents("text.inc") will be looked for in: 1. the current working directory 2. the included dirs So, if you're running the script like: [user@server /]# cd / [user@server /]# php -q /var/www/html/scripts/mail.php then you're actually working in /, so it's looking for "text.inc" in: /text.inc and in all include-paths. Now, usually you can fix such a thing by using: chdir(dirname(__FILE__)); at the top of the script to force it to work in the directory the script itself is in. However, when you call it from the browser, via the server, it will always run from the path the script is located in. (the extra chdir() won't cause any problems though) Hope that helps, - Tul

« previous php.general (#195215) next »