Jump to content

cactuscake

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

cactuscake's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I recently changed something in an old script of mine and it doesn't work properly anymore. I don't know what I did, and I don't have a backup, oops! The code below is supposed to take inputs from a web form and turn them into an e-postcard, attaching and sending it as a jpeg on an email, ideally to be displayed inline. $name = $_POST['sendername']; $to = $_POST['recipient']; $from = $_POST['senderemail']; $subject = basename( $name)." has sent you a jCard!"; $message = $_POST['text']; $bcc = $_POST['bcc']; $finalimage = $_POST['finalimage']; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r', time())); //define the headers we want passed. Note that they are separated with rn $headers = "From: ".$name." <".$from.">\r\nReply-To: ".$name." <".$from.">\r\nBcc: ".$bcc."\r\nX-Mailer: PHP/".phpversion();""; //add boundary string and mime type specification $headers .= "\r\nContent-Type: multipart/mixed; boundary='PHP-mixed-".$random_hash."'"; //read the attachment file contents into a string, //encode it with MIME base64, //and split it into smaller chunks $attachment = chunk_split(base64_encode(file_get_contents($finalimage))); //define the body of the message. ob_start(); //Turn on output buffering ?> --PHP-mixed-<?php echo $random_hash; ?> Content-Type: multipart/alternative; boundary='PHP-alt-<?php echo $random_hash; ?>' --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/plain; charset='iso-8859-1'; Content-Transfer-Encoding: 7bit <?php echo $name; ?> sent you a jCard, click the attachment to view it. Send your own jCards at www.j-cards.co.uk! --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/html; charset='iso-8859-1'; Content-Transfer-Encoding: 7bit <p><?php echo $name; ?> sent you this jCard:</p> <img src="cid:<?php echo $random_hash; ?>.jCard.jpg" /> <p>Send your own jCards at <a href="http://www.j-cards.co.uk">j-cards.co.uk</a>!</p> --PHP-alt-<?php echo $random_hash; ?>-- --PHP-mixed-<?php echo $random_hash; ?> Content-Type: image/jpeg; name='jCard.jpg' Content-Transfer-Encoding: base64 Content-ID: <<?php echo $random_hash; ?>.jCard.jpg> Content-Disposition: attachment; filename='/jCard.jpg' <?php echo $attachment; ?> --PHP-mixed-<?php echo $random_hash; ?>-- <?php //copy current buffer contents into $message variable and delete current output buffer $message = ob_get_clean(); //send the email $mail_sent = @mail( $to, $subject, $message, $headers ); //if the message is sent successfully return success page html. Otherwise return send fail html. echo $mail_sent ? "<html> snip... The email gets sent, and the source of the email looks identical to that of previous correctly displayed versions, but for some reason the email reader no longer renders the html, instead it just shows plain text, so it looks like the source just without headers - e.g.: So everything is being sent, it's just an issue of getting it read correctly by the email program (worked before in gmail and hotmail). So I think it's an issue with the headers or boundary string I'm using, but they look alright to me, I just can't see what I've done wrong. Any ideas?
  2. Try adding the red part above. Or just remove the second instance of $field1_name altogether, at the moment your script is producing an img src of thumbs/nophoto.jpgblahblahblah (where blahblahblah is whatever $field1_name's value is) it's not a valid file extension.
  3. I get this: Fatal error: Call to undefined function imagettftext() in /www/110mb.com/j/o/e/m/a/l/p/a/joemalpass/htdocs/fonttest.php on line 22 (using the following test script) <?php // Set the content-type header('Content-type: image/png'); // Create the image $im = imagecreatetruecolor(400, 30); // Create some colors $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); $black = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 399, 29, $white); // The text to draw $text = 'Testing...'; // Replace path by your own font path $font = 'arial.ttf'; // Add some shadow to the text imagettftext($im, 20, 0, 11, 21, $grey, $font, $text); // Add the text imagettftext($im, 20, 0, 10, 20, $black, $font, $text); // Using imagepng() results in clearer text compared with imagejpeg() imagepng($im); imagedestroy($im); ?> Other sources suggest I need other GD thingies enabled, but I don't have control over the configuration so I can't enable them.
  4. Ah, now I remember why I couldn't sort this out before - I don't think the required GD stuff is enabled on my server (php config below). Are there any workarounds for this? './configure' '--enable-memory-limit' '--disable-debug' '--with-regex=php' '--disable-rpath' '--disable-static' '--with-pic' '--with-layout=GNU' '--with-pear=/usr/share/php' '--enable-calendar' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--enable-track-vars' '--enable-trans-sid' '--enable-bcmath' '--with-bz2' '--enable-ctype' '--with-db4' '--with-iconv' '--enable-exif' '--enable-filepro' '--enable-ftp' '--with-gettext' '--enable-mbstring' '--with-pcre-regex=/usr' '--enable-shmop' '--enable-sockets' '--enable-wddx' '--disable-xml' '--with-expat-dir=/usr' '--with-xmlrpc' '--enable-yp' '--enable-dio' '--with-zlib' '--without-pgsql' '--with-kerberos=/usr' '--with-openssl=/usr' '--with-zip=/usr' '--enable-dbx' '--with-mime-magic=/usr/share/misc/file/magic.mime' '--with-exec-dir=/usr/lib/php4/libexec' '--prefix=/usr' '--with-apxs2=/usr/bin/apxs2' '--with-config-file-path=/etc/php4/apache2' '--with-jpeg-dir=/usr/lib' '--with-gd' '--with-curl' '--with-mysql'
  5. Me again! Received some useful help from these forums in the last couple of days so I'm back with another question. The snippet of code below pieces together an image using an uploaded image file, a bunch of user-defined form field values, and some server side image resources. It works, but I've been wanting to change the font from the default (rather ugly) to something like arial or courier, and maybe at a later stage give the user the option to choose the font from a short list. Not asking someone to do it for me, but if you've done this sort of thing before perhaps point me in the direction of any resources that helped? Thanks. <?php $imagepath = $_FILES['fileatt']['tmp_name']; $now = time(); // Load image $image = open_image($imagepath); if ($image == false) { die ('<strong>Invalid type/size or no image file specified. Please go back and try again with an image file under 2Mb.</strong>'); } // Get original width and height $width = imagesx($image); $height = imagesy($image); if ($width > $height) { $new_width = floatval($_POST['new_width']); $new_height = $height * ($new_width/$width); } // New height? Calculate new width else { $new_height = floatval($_POST['new_height']); $new_width = $width * ($new_height/$height); } // Resample $image_resized = imagecreatetruecolor($new_width + 358, $new_height + ; $bgColor = imagecolorallocate($image_resized, 255,255,255); $trans = imagecolorallocatealpha ($image_resized, 255, 255, 255, 127); imagefill($image_resized, 0,0 , $trans); imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // Merge with bottom shadow $shadowbot = imagecreatefromgif ( "card_graphics/shadowbot.gif" ); imagecopy($image_resized, $shadowbot, 0, $new_height, 0, 0, $new_width, ; // Merge with side shadow $shadowrit = imagecreatefromgif ( "card_graphics/shadowrit.gif" ); imagecopy($image_resized, $shadowrit, $new_width + 350, 0, 0, 0, 8, $new_height); // Merge with corner shadow $shadowcor = imagecreatefromgif ( "card_graphics/shadowcor.gif" ); imagecopy($image_resized, $shadowcor, $new_width, $new_height, 0, 0, 358, ; // Merge with postmark $postmark = imagecreatefromgif ( "card_graphics/postmark.gif" ); imagecopy($image_resized, $postmark, $new_width, 0, 0, 0, 350, 75); // Merge with message $string = stripslashes($_POST['text']); $font = 5; $line_height = ImageFontheight($font) + 5; $padding = (is_numeric($padding)) ? $padding : 0; $text = wordwrap($string, ((315 - (1.5 * $padding))/ImageFontWidth($font))); $lines = explode("\n", $text); imagefill($image_resized, 0, 0, $trans); $i = 90; foreach($lines as $line){ imagestring($image_resized, $font, ($new_width +15), $i, trim($line), $colour); $i += $line_height; } $targetpath = "sentcards/". $now . basename( $_FILES['fileatt']['name']); imagejpeg ($image_resized, $targetpath, 100); ?>
  6. Couldn't get my original code to behave with the MIME header coming first, for some reason it was sending the mail as text/plain if I changed pretty much anything from that original layout. In the end I borrowed a completely new code snippet and it seems to work much better. Posting it here in case anyone else comes across the same problem in the future. I've tailored it for an image attachment that I want to be able to show inline in the body of the html email, you need to change the content-disposition if you don't want it to behave that way. <?php $name = $_POST['sendername']; $to = $_POST['recipient']; $from = $_POST['senderemail']; $subject = basename( $name)." sent you a card!"; $message = $_POST['text']; $bcc = $_POST['bcc']; $finalimage = $_POST['finalimage']; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r', time())); //define the headers we want passed. Note that they are separated with \r\n $headers = "From: ".$name." <".$from.">\r\nReply-To: ".$name." <".$from.">\r\nBcc: ".$bcc.""; //add boundary string and mime type specification $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\""; //read the attachment file contents into a string, //encode it with MIME base64, //and split it into smaller chunks $attachment = chunk_split(base64_encode(file_get_contents($finalimage))); //define the body of the message. ob_start(); //Turn on output buffering ?> --PHP-mixed-<?php echo $random_hash; ?> Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>" --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Plain text email content --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit <p>html email content</p> <img src="cid:<?php echo $random_hash; ?>.image.jpg" /> <p>more html content below image</p> --PHP-alt-<?php echo $random_hash; ?>-- --PHP-mixed-<?php echo $random_hash; ?> Content-Type: image/jpeg; name="image.jpg" Content-Transfer-Encoding: base64 Content-ID: <<?php echo $random_hash; ?>.image.jpg> Content-Disposition: inline; filename="/image.jpg" <?php echo $attachment; ?> --PHP-mixed-<?php echo $random_hash; ?>-- <?php //copy current buffer contents into $message variable and delete current output buffer $message = ob_get_clean(); //send the email $mail_sent = @mail( $to, $subject, $message, $headers ); //if the message is sent successfully return mail sent message. Otherwise return fail message. echo $mail_sent ? "Mail sent" : "Mail failed"; ?>
  7. Tried this: $headers = "From: ". $name. " <". $from .">\r\n"; $headers .= "Bcc: ". $bcc ."\r\n"; But it sends the email as plain text While I'm here - what is the difference between \r\n and just \n?
  8. A bit confused about this... Below is a copy of some code on my website, currently works without a hitch, however, when I try to add a bcc address to the headers it either sends the entire message in text/plain or it messes up the 'from' field or it just doesn't work at all (depending on the syntax I've tried using). Can anyone suggest a way of slipping a bcc header in without screwing anything up? <?php $name = $_POST['sendername']; $to = $_POST['recipient']; $from = $_POST['senderemail']; $subject = basename( $name)." has sent you a jCard!"; $message = $_POST['text']; $bcc = $_POST['bcc']; $finalimage = $_POST['finalimage']; $headers = "From: ". $name. " <". $from .">\n"; // Read the file to be attached ('rb' = read binary) $file = fopen($finalimage,'rb'); $data = fread($file,filesize($finalimage)); fclose($file); // Generate a boundary string $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // Add the headers for a file attachment $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; // Add a multipart boundary above the plain message $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $name . " sent you this jCard:\n\n"; // Base64 encode the file data $data = chunk_split(base64_encode($data)); // Add file attachment to the message $message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"jcard.jpg\"\n" . "Content-Disposition: attachment;\n" . " filename=\"jcard.jpg\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; // Send the message $ok = @mail($to, $subject, $message, $headers); if ($ok) { <snip>
  9. Using onclick because the input type is an image... can't get into my host server at the moment to test a simple submit button but will try that as soon as I'm back in. uggh! Looks like the server has been down for several hours... I guess I'm going to have to wait until tomorrow to sort it out.
  10. Got a problem with a php website I'm creating. In a nutshell, the first page is entirely html and calls a php script to process an uploaded file and some form fields using POST. After validating the uploaded file the script echos a new page with a new form containing hidden inputs to carry forward the extra information provided in the original form (this was easier than getting my head around cookies). It works, because when I view the generated source all of the hidden input values have been populated with the correct information. The problem I am having is with the next part of the process - the echoed page includes a new button that is supposed to call a separate php script, using the new form values. But when the button is clicked, it executes the existing php script again (and fails on the validation) instead of running the correct script as referenced in the onClick attribute of the button. Any idea what I'm doing wrong? or why it is behaving like this?
×
×
  • 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.