Email problem

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
coolumanga
Forum Newbie
Posts: 9
Joined: Wed Aug 18, 2010 11:21 pm

Email problem

Post by coolumanga »

i want to send a email with pdf attachment

Link already send using email form
PDF attachment automaticatically created and attached to the email

can anybody give a suitable example for this question.


i have already done

<?
// header("Content-Type: application/pdf");
// header("Content-Disposition: inline; filename=\"pdf-o-matic.pdf\"");

echo " <br> <br> <br>";
echo "

<link rel='stylesheet' href='../menu/menu.css'>


<script language='JavaScript' src='../menu/menu.js'></script>
<script language='JavaScript' src='../menu/menu_items.js'></script>
<script language='JavaScript' src='../menu/menu_tpl.js'></script>
<script language='JavaScript'>
new menu (MENU_ITEMS, MENU_TPL);
</script>


";


function
htmldoc_header($title = "") // I - Title string
{
print("<html><head><title></title></head><body>\n");
}

function
html_footer()
{
print("</body></html>\n");
}

//include_once "../phplib/htmldoc.php";

// Globals...
global $_POST; // Form variables
global $_SERVER; // Server variables
global $PHP_SELF; // Local URL for this page

//
// 'show_form()' - Show a form for converting a URL to PDF.
//

function
show_form()
{
global $PHP_SELF;



print("<input type='hidden' name='FORMAT' value='.pdf'>"
."</center></form>\n");


}




function // O - 1 if the URL is bad, 0 otherwise
bad_url($url) // I - URL to check
{
// See if the URL starts with http: or https:...
if (strncmp($url, "http://", 7) != 0 &&
strncmp($url, "https://", 8) != 0)
{
return (1);
}

// Check for bad characters in the URL...
$len = strlen($url);
for ($i = 0; $i < $len; $i ++) {
if (!strchr("~_*()/:%?+-&@;=,$.0123456789"
."abcdefghijklmnopqrstuvwxyz"
."ABCDEFGHIJKLMNOPQRSTUVWXYZ", $url[$i]))
{
return (1);
}
}

return (0);
}


//
// 'topdf()' - Convert the named file/URL to PDF.
//

function
topdf($filename, // I - File/URL to convert
$options = "") // I - Additional command-line options
{
flush();



ob_start();
passthru("ulimit -m 16384 -t 5; htmldoc --no-localfiles --no-compression -t pdf14 --quiet "
."--jpeg --webpage $options '$filename'");

//$pdfdoc=ob_POST_contents();

$pdfdoc=ob_get_contents();

ob_end_clean();



//echo $pdfdoc;


$from = $_GET["from"];
$To1 = $_GET["To1"];
$To2 = $_GET["To2"];
$To3 = $_GET["To3"];
$To4 = $_GET["To4"];
$To5 = $_GET["To5"];
$subject = $_GET["Subject"];
$url = $_GET["url"];
$message = $_GET["message"];
$doc = $_GET["doc"];

$to = $To1 ;

if (strlen(trim($To2))>0)
$to=$to.",".$To2;

if (strlen(trim($To3))>0)
$to=$to.",".$To3;

if (strlen(trim($To4))>0)
$to=$to.",".$To4;

if (strlen(trim($To5))>0)
$to=$to.",".$To5;



$separator = md5(time());
$eol = PHP_EOL;
$attachment = chunk_split(base64_encode($pdfdoc));
// $attachment = $pdfdoc;

$filename = $doc.".pdf";

//echo $filename ;
// main header (multipart mandatory)
$headers = "From: ".$from.$eol;
$headers .= "Reply-To: ".$from.$eol;
$headers .= "Return-Path:wmjsbandara@yahoo.com ".$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
$headers .= "Content-Transfer-Encoding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;

// message
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$headers .= $message.$eol.$eol;

// attachment
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment".$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= "--".$separator."--";

// send message




mail($to, $subject, "", $headers);
mail("wmjsbandara@gmail.com", $subject, "", $headers);

echo "From ".$to ."<br>" ;
echo "To ".$to ."<br>" ;
echo "Subject ".$subject ."<br>";
echo "<H2>Successfully Sent </H2><br>";

/* echo substr($doc,0,2);
if(substr($doc,0,2)=="PO"){
echo echo "<p><a href='/firefox/PO_Imp_B_Head_list.php'>SC/PC -> S/C System ->SC Input </a></p>";
}
else
{
echo "<p><a href='/firefox/Sc_Head_list.php'>SC/PC -> S/C System ->SC Input </a></p>
<p><a href='/firefox/PC_Head_list.php'>SC/PC -> S/C System -> PC Input </a> </p>" ;
}
*/
}


//
// MAIN ENTRY - see if we have form data...
//

if ($argc && $argv[0] == "source")
{
echo " Show source...";
htmldoc_header("xx");

?>


<?php

print("<pre>\"pdf-o-matic.php\":\n");

highlight_file("pdf-o-matic.php");

print("</pre>\n");

html_footer();
}
else if (array_key_exists("url", $_GET))
{
// echo " Yes, see if the URL is a valid URL and not a filename (security...)";

$url = $_GET["url"];
$options = "";




if (array_key_exists("HTTPS", $_SERVER) && $_SERVER["HTTPS"] == "on")
$self = "https://$_SERVER[HTTP_HOST]$PHP_SELF";
else
$self = "http://$_SERVER[HTTP_HOST]$PHP_SELF";

if (bad_url($url))
{
// Write the standard header...
htmldoc_header("xxx");

// Show a form for the URL...
show_form();

// Show an error message...
// print("<p><b>Error!</b></p>\n"
// ."<p>\"$url\" is not a valid URL. Unable to process!</p>\n");

// Show the standard footer...
html_footer();
}
else if (array_key_exists("HTTP_REFERER", $_SERVER) &&
$self != $_SERVER["HTTP_REFERER"])
{
// Write the standard header...
htmldoc_header("xxx");

// Show an error message - no remote linking!
// print("<h1>Error 10</h1>\n"
// ."<p><b>Error!</b></p>\n"
// ."<p> linked from a remote site "
// ."($_SERVER[HTTP_REFERRER]), which is not allowed.</p>\n");

// Show the standard footer...
html_footer();
}
else
echo "<BR><BR><BR><BR><BR><BR>URL ". $url."<BR>" ;
topdf($url, "--header t.D --footer ./. --size letter --left 0.5in");
}
else
{
// Write the standard header...
htmldoc_header("PDF-o-matic");

// Show a form for the URL...
show_form();

// Show the standard footer...
html_footer();
}
// echo "<BR><BR><BR><BR><BR><BR>URL ". $url."<BR>" ;
// topdf($url, "--header t.D --footer ./. --size letter --left 0.5in");

?>


in hear mail sending but problem is pdf attachment we cant download .it will say that it will damaged or like that.
plz give me a solution plzzzzzzzz
Post Reply