Jump to content

Grab a line as a subject


webstar

Recommended Posts

How can i Make this code below grab the 3rd line of the file I am feeding through it and make it the subject line of the email?  I'm kinda php dumb and this is likely really simple.

#!/usr/bin/php
<?php


# E-mail recipient(s).  Separate each address with a comma and a space.
$emailrecip = "REMOVED";

# E-mail subject line.
$emailsubject = "REMOVED";

# E-mail From name.
$emailfromname = "REMOVED";

# E-mail From address.
$emailfromaddr = "REMOVED";



$fp = fopen('php://stdin','r');
  $data = "";
  while(!feof($fp)) {
      $data .= fgets($fp,4096);
  }
  fclose($fp);




	$timestamp = "REMOVED";
$timestamp .= date("D, j M Y G:i:s O  ");
$timestamp .= "\n";
$timestamp .= "Emailed to you at: %EMAILSTAMP%";
$timestamp .= "\n";


# Send the e-mail.
			$subject = $emailsubject;
	        $recipient = $emailrecip;
	        $body_of_email = $timestamp;
			$body_of_email .= trim($data);

	        $header = 'From: "' . $emailfromname . '" <' . $emailfromaddr . '>';
	        $header .= "\n"; 
	        $header .= "X-Priority: 1";
	        $header .= "\n";
		
 	        mail ($recipient, $subject, $body_of_email, $header);
	
	        echo ("E-mail sent.");
	
?>
Link to comment
Share on other sites

Use fgets, each time it is called it returns the next line. Everytime you get a new line increment a counter, when the counter hits 3, this will be the 3rd line then set the $subject

$data = '';
$i = 0;

while (false !== ($line = fgets(STDIN)))
{
    $data .= $line;

    /// if we are on the 3rd line, set the subject
    if(++$i == 3)
       $subject = $line;
}
Edited by Ch0cu3r
Link to comment
Share on other sites

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.