Jump to content

file_get_contents doesn't seem to get the file contents (help!)


Recommended Posts

Hello to one and all,

  newbie/hobbiest here - I am attempting to adjust the mail function in my scripts so that rather then having to constantly update 30 different scripts I can have one text doc that they can all draw on using the file_get_contents function to read in the email address as a string and send the notices to those email address, however I am getting an error when I attempt this which reads as follows: Warning: file_get_contents(email_addressestxt) [function.file-get-contents]: failed to open stream: No such file or directory in /home/maxster/xaviers-children.net/modMail/charRequest.php  on line 2

 

$emailAddresses = file_get_contents(email_addresses.txt);
  $to = $emailAddresses;
[\code]

Error produced: 
Warning: file_get_contents(email_addressestxt) [function.file-get-contents]: failed to open stream: No such file or directory in /home/maxster/xaviers-children.net/modMail/charRequest.php  on line 21


text file being read:
[code]
Ditko <chezshire@gmail.com>, Bill<example@example.com>

 

 

Full Php Script:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Xavier's Children » Character Request Sent!</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body align="center">
  <h2 align="center">Xavier's Children » Character Request Sent!</h2>

<?php
  $name = $_POST['namePlayer'];
  $topic = $_POST['nameTopic'];
  $char_overview = $_POST['charOverview'];
  $char_requested = $_POST['charRequested'];
  $email = $_POST['email'];
  $oc_fc = $_POST['OcFc'];


  //$emailAddresses = file_get_contents(email_addresses.txt);
  //$to = $emailAddresses;


  $to = 'ADAMS <doyleconlan@ireland.com>, DITKO <chezshire@gmail.com>, VAUGHAN <vismaior2000@yahoo.com>';
  $subject = 'Xavier\'s Children » Character Request ' . $oc_fc . ' - ' . $char_requested;
  $msg = "FROM: $name \n \n";
  $msg .= (empty($oc_fc)) ? "" : "OC or FC: $oc_fc  \n \n";
  $msg .= (empty($char_requested)) ? "" : "CHARACTER NAME: $char_requested  \n \n";
  $msg .= "CHARACTER OVERVIEW: $char_overview \n \n";


mail($to, $subject, $msg, 'From:' . $email);


  echo 'Your petition to play <strong>' . $char_requested . '</strong> has been submitted and forward to the appropriate member\'s staff members ' . $name . '. Please allow us to review and consider your request. We will attempt to contact you with a decision within twenty-four hours.<br /> <br />';
?>

<p align=center><a href=../messages.php>RETURN TO XAVIER'S CHILDREN</a></p>

</body>
</html>

 

Hmms,

 

So should I change this line of code: $emailAddresses = file_get_contents(email_addresses.txt);

to this: $emailAddresses = file_get_contents(email_addresses.\txt);

 

There is a period in the line of code - is that causing a concatenation thus erring out script?

 

-Chez

You are missing quotes around the file name, making php think it is a defined constant (if error reporting was set to E_ALL you would see some notice messages alerting you to this problem.)

 

Edit: Specifically -

Notice: Use of undefined constant email_addresses - assumed 'email_addresses' in your_file.php on line x

 

Notice: Use of undefined constant txt - assumed 'txt' in your_file.php on line x

So I should change this line of code: $emailAddresses = file_get_contents(email_addresses.txt);

to this: $emailAddresses = file_get_contents("email_addresses.txt");

 

Am i understanding you correctly?

Thank you very much for the help

-Chez

Did you try that to see if it worked or not?

 

One of the points of programming is you can try ideas and immediately observe the results to learn if your idea was correct or not. You don't need to wait around in a programming forum to learn answers to basic questions like that.

Yes I did test it, but it didn't appear to work. But following the guidance provided here, I looked at my text file being read in and realized I had some quote marks in the text file what was causing my script to error out.

 

Thank you everyone

-Chez

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.