Отправить два вложения по электронной почте, переполнение стека

Нужен ваш совет о том, как сделать письмо с двумя вложениями (одноразовые ссылки для скачивания) и отправить его с помощью PHP.

На данный момент у меня есть код, который отправляет только одну ссылку, и она отлично работает. На самом деле, как я построил свою программу, у меня есть два PHP-файла: url.php а также get_file.php, В get_file.php Я создаю одноразовый загружаемый URL для документа, который я хочу отправить по электронной почте, используя url.php.
Вот код get_file.php:

<?php

/* Retrieve the given token: */
$token = $_GET['q'];

if( strlen($token)<32 )
{
die("Invalid token!");
}

/* Define the file for download: */
$secretfile = "file1.pdf";

/* This variable is used to determine if the token is valid or not: */
$valid = 0;

/* Define what file holds the ids. */
$file = "urls.txt";

/* Read the whole token-file into the variable $lines: */
$lines = file($file);

/* Truncate the token-file, and open it for writing: */
if( !($fd = fopen("urls.txt","w")) )
die("Could not open $file for writing!");

/* Aquire exclusive lock on $file. */
if( !(flock($fd,LOCK_EX)) )
die("Could not equire exclusive lock on $file!");

/* Loop through all tokens in the token-file: */
for( $i = 0; $i < count($lines); $i++ )
{
/* Is the current token the same as the one defined in $token? */
if( $token == rtrim($lines[$i]) )
{
$valid = 1;
}
/* The code below will only get executed if $token does NOT match the
current token in the token file. The result of this will be that
a valid token will not be written to the token file, and will
therefore only be valid once. */
else
{
fwrite($fd,$lines[$i]);
}
}

/* We're done writing to $file, so it's safe release the lock. */
if( !(flock($fd,LOCK_UN)) )
die("Could not release lock on $file!");

/* Save and close the token file: */
if( !(fclose($fd)) )
die("Could not close file pointer for $file!");

/* If there was a valid token in $token, output the secret file: */
if( $valid )
{
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($secretfile).'"';
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
/*header('Content-Length: ' . filesize($file));*/
readfile($secretfile);
}
else
{
print "Invalid URL!";
}

?>

Вот код url.php:

<?php

$token = md5(uniqid(rand(),1));

$file = "urls.txt";
if( !($fd = fopen($file,"a")) )
die("Could not open $file!");
if( !(flock($fd,LOCK_EX)) )
die("Could not aquire exclusive lock on $file!");
if( !(fwrite($fd,$token."\n")) )
die("Could not write to $file!");
if( !(flock($fd,LOCK_UN)) )
die("Could not release lock on $file!");
if( !(fclose($fd)) )
die("Could not close file pointer for $file!");

$cwd = substr($_SERVER['PHP_SELF'],0,strrpos($_SERVER['PHP_SELF'],"/"));

function clean_string($string) {

$bad = array("content-type","bcc:","to:","cc:","href");

return str_replace($bad,"",$string);

}$a = "http://".$_SERVER['HTTP_HOST']."$cwd/get_file.php?q=$token";

$email_to = $_POST['email'];
$email_to_bcc = "mail@mail.com";
$email_from = "mail@mail.com";
$email_subject = "download link";
$email_message = "Thank you for your purchase.\n\n";
$comments = $a;
$email_message .= "Here is your one-time link to download the file:\n".clean_string($comments);

$headers = 'From: '.$email_from."\r\n" .

'BCC: '.$email_to_bcc."\r\n" .

'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();

mail($email_to, $email_subject, $email_message, $headers);
?>

Вопрос в том, могу ли я в моем файле get_file.php определить два файла для загрузки, создать две загружаемые ссылки и затем создать два вложения в заголовке?

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector