Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript automatic pdf download Reply To: automatic pdf download

#250166
chauhanheena
Participant

Hi
I used the below code

<?php
if(!$_POST) exit;

function isEmail($email) {
    return(preg_match("/^[-_.[:alnum:]][email protected]((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}

if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");

$source = $_POST['source'];
$cname   = $_POST['cname']; 
$product = $_POST['product'];
$phone = $_POST['phone'];
$mobile = $_POST['mobile'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$remarks = $_POST['remarks'];
$verify   = $_POST['verify'];

if(trim($fname) == '') {
    echo '<div class="error_message">You must enter your first name.</div>';
    exit();
} else if(trim($lname) == '') {
    echo '<div class="error_message">You must enter your last name.</div>';
    exit();
} else if(trim($cname) == '') {
    echo '<div class="error_message">You must enter your company name.</div>';
    exit();
} else if(trim($phone) == '') {
    echo '<div class="error_message">You must enter your phone no.</div>';
    exit();
} else if(trim($mobile) == '') {
    echo '<div class="error_message">You must enter your mobile no.</div>';
    exit();
} else if(trim($email) == '') {
    echo '<div class="error_message">Please enter a valid email address.</div>';
    exit();
} else if(!isEmail($email)) {
    echo '<div class="error_message">You have enter an invalid e-mail address, try again.</div>';
    exit();
}

if(get_magic_quotes_gpc()) {
    $remarks = stripslashes(remarks);
}

$address = "[email protected]";

$e_subject = $cname . '/' . $fname . ' ' . $lname . ' ' . $source . ' ';

$e_source = "Source: $source" . PHP_EOL . PHP_EOL;
$e_cname = "Custome Name: $cname" . PHP_EOL . PHP_EOL;
$e_product = "Product: $product" . PHP_EOL . PHP_EOL;
$e_phone = "Phone No.: $phone" . PHP_EOL . PHP_EOL;
$e_mobile = "Mobile: $mobile" . PHP_EOL . PHP_EOL;
$e_name = "Contact Person: $fname $lname" . PHP_EOL . PHP_EOL;
$e_email = "Email: $email" . PHP_EOL . PHP_EOL;
$e_remarks = "Remarks: $remarks";

$msg = $e_source . $e_cname . $e_product . $e_phone . $e_mobile . $e_name . $e_email . $e_remarks;

$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;

if(mail($address, $e_subject, $msg, $headers)) {

    // Email has sent successfully, echo a success page.

    echo "<fieldset>";
    echo "<div id='success_page'>";
    echo "<h4 class='highlight'>Thank you! <strong>$fname</strong>. PDF download will automatically start now.</h4>";
    echo "</div>";
    echo "</fieldset>";


header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="BESTBUILD-Wall-Putty-FN.pdf"');
header('Expires: 0');
header('Cache-Control: no-cache, no-store, must-revalidate');
header('Pragma: no-cache');
readfile('BESTBUILD-Wall-Putty-FN.pdf');

} else {
    echo 'ERROR!';
}


but the result is, an mail is sent and on the success page the following is shown.

Thank you! Heena. PDF download will automatically start now.

%PDF-1.5 %���� 73 0 obj << /Linearized 1 /L 1575021 /H [ 1901 415 ] /O 75 /E 1528187 /N 3 /T 1573434 >> endobj xref 73 58 0000000017 00000 n 0000001630 00000 n 0000002316 00000 n 0000002881 00000 n 0000002952 00000 n 0000003026 00000 n 0000003134 00000 n 0000003200 00000 n 0000003630 00000 n 0000004109 00000 n 0000036414 00000 n 0000036454 00000 n 0000037290 00000 n 0000037364 00000 n 0000037444 00000 n 0000102395 00000 n 0000134964 00000 n 0000138623 00000 n 0000138785 00000 n 0000138825 00000 n 0001504275 00000 n 0001504388 00000 n 0001504492 00000 n 0001504654 00000 n 0001504810 00000 n 0001504938 00000 n 0001505038 00000 n 0001505140 00000 n 0001505300 00000 n 0001505458 00000 n 0001505621 00000 n 0001505736 00000 n 0001505845 00000 n 0001506008 00000 n 0001506123 00000 n 0001506232 00000 n 0001506394 00000 n 0001506557 00000 n 0001506731 00000 n 0001507340 00000 n 0001507509 00000 n 0001507592 00000 n 0001507877 00000 n 0001512895 00000 n 0001513272 00000 n 0001513435 00000 n 0001513789 00000 n 0001513947 00000 n 0001514221 00000 n 0001514963 00000 n 0001515068 00000 n 0001515230 00000 n 0001515563 00000 n 0001515720 00000 n 0001515996 00000 n 0001516508 00000 n 0001516565 00000 n 0000001901 00000 n trailer << /Size 131 /Prev 1573423 /Info 72 0 R /Root 74 0 R /ID [] >> startxref 0 %%EOF 74 0 obj << /Type /Catalog /Pages 62 0 R /Names << /Dests 67 0 R >> /Outlines 63 0 R /OCProperties << /D << /Order [ 86 0 R 59 0 R 60 0 R 61 0 R ] /ON [ 86 0 R 59 0 R 60 0 R 61 0 R ] /OFF [ ] /RBGroups [ ] >> /OCGs [ 86 0 R 59 0 R 60 0 R 61 0 R ] >> >> endobj 130 0 obj << /S 155 /O 367 /Filter /FlateDecode /Length 316 >> stream x���M(Dq����|gF�i�,�XZ�(䩷��d��xYMIi��ެ���D�lX%��d�j�Ӱ�d!I����X�u���{���\�8��$�o�$�Bý����$2��x,��+i�ƅE�ͻ~0|�,?FNg����Vŭo��������R,�=�3Uw8��.M4��b����/Y�����)��^�HY� \��5�*��t\�<�]�BR�T!�a�3�yp�’,V� zE|Ѓx” ���Y����JQ�2nSD,E�a�J.˨.��ݨ{����й�o��]��͖(�ɒD\��w��J#R�_{}����KM��<�O� endstream endobj 75 0 obj << /Type /Page /CropBox [ 0 0 595.276 822.047 ] /MediaBox [ 0 0 595.276 822.047 ] /Resources << /ExtGState << /GS11 76 0 R /GS13 77 0 R /GS71 78 0 R >> /Properties << /Pr12 86 0 R >> /XObject << /X0