ACertainTrigger Posted February 24, 2007 Share Posted February 24, 2007 Hey all, newbie to the forum here I've got a set of htm files which I use as includes on some of my pages, but I want to be able to use them when sending an email but I can't see a way how. I've been trying to assign them to my $message for sending in the mail() but I can't see a way of doing this. Is there a better way? Any help appreciated Thanks Quote Link to comment Share on other sites More sharing options...
Yesideez Posted February 24, 2007 Share Posted February 24, 2007 Do you mean you want to include them AS an email and not as attachments? Quote Link to comment Share on other sites More sharing options...
ACertainTrigger Posted February 24, 2007 Author Share Posted February 24, 2007 I don't mind which, as long as they display as the email. I'm writing a test, and the different results are include files, so at the moment I have the results page include the relevant htm file for the results that fit. I want the user to also recieve an email with the results, but as the results are stored as htm includes I'm not sure how to get them in the body of the email. I don't want the whole email to be the htm file, just a part of it, as I want the first part to be "Dear $name" etc. Hence why i was trying to set it all as a variable. Any ideas? Thanks ACT Quote Link to comment Share on other sites More sharing options...
xyn Posted February 24, 2007 Share Posted February 24, 2007 Do you want to send the email as HTML or attach them as a file attachment? Ash Quote Link to comment Share on other sites More sharing options...
ACertainTrigger Posted February 24, 2007 Author Share Posted February 24, 2007 I want to send an html email, where a part of the body is the contents of a results.inc.htm I know this doesn't work, but something like this just so you can see the logic $message = "<p>Dear $name</p> <p>Thanks for taking the test, here are your results:</p>" $message .= include('yourResults.inc.htm'); It would be more complex than that because the include would differ depending on the results, but hopefully this makes sense Quote Link to comment Share on other sites More sharing options...
Yesideez Posted February 24, 2007 Share Posted February 24, 2007 Ah! I was going to post this: $header='MIME-Version: 1.0'."\r\n".'Content-type: text/html; charset=iso-8859-1'."\r\nFrom: Someone <someone@somewhere.net>\r\n"; mail($recipient,$subject,$message,$header) That's to send your email as an HTML file, basically allowing you to send an entire web page as an email. I think I understand what you are requesting now Let's say you have the following data: Recipient's name is stored as $username Recipient's email is stored as $useremail Recipient's address is stored as $useraddr Recipient's age is stored as $userage Have a play with this and see how you get on. $header="From: Someone <someone@somewhere.net>\r\n"; $subject="Please verify your address"; $message="Dear $username,\n\nI see your age is $userage and your address is:\n$useraddr\n\nPlease let us know if these details are incorrect."; mail($useremail,$subject,$message,$header) Quote Link to comment Share on other sites More sharing options...
skali Posted February 24, 2007 Share Posted February 24, 2007 You will need to set the content type of mail in header like in the code below. $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; Now just add html content to an string, and this string will be message that will be sent with the mail. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted February 24, 2007 Share Posted February 24, 2007 You will need to set the content type of mail in header like in the code below. $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; Now just add html content to an string, and this string will be message that will be sent with the mail. Just like what I "was" going to post. Quote Link to comment Share on other sites More sharing options...
ACertainTrigger Posted February 24, 2007 Author Share Posted February 24, 2007 You will need to set the content type of mail in header like in the code below. $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; Now just add html content to an string, and this string will be message that will be sent with the mail. How do I add the html content (which is inside a testResults.inc.htm) to a string? This is the bit I can't fathom. I've read something about output buffering, is this the right way? Quote Link to comment Share on other sites More sharing options...
Yesideez Posted February 24, 2007 Share Posted February 24, 2007 ACertainTrigger, posting some code will help otherwise how are myself or skali going to know? Quote Link to comment Share on other sites More sharing options...
ACertainTrigger Posted February 24, 2007 Author Share Posted February 24, 2007 ACertainTrigger, posting some code will help otherwise how are myself or skali going to know? Sorry guys, this is where I'm up to so far but it doesn't work. //email the user if ($emailSend == "yes") { $headers = "From: ". $emailFrom . "\r\n" . "Reply-To: $email" . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $to = $_POST['email']; $subject = "Your Results"; $message = "<h1>Your Results</h1>"; $message .= include('profiles/pca' . $pcatype.'.inc.htm'); mail($to,$subject,$message,$headers); }; I hope this makes a little more sense Quote Link to comment Share on other sites More sharing options...
Yesideez Posted February 24, 2007 Share Posted February 24, 2007 $headers='MIME-Version: 1.0'."\r\n"; $headers.='Content-type: text/html; charset=iso-8859-1'."\r\n"; $headers.="From: ACertainTrigger <".$emailFrom.">\r\n"; Try changing your headers line to that - personally I'm not sure about how you're including the HTML file into the email as I must admit I've never tried using include() like that! Quote Link to comment Share on other sites More sharing options...
Yesideez Posted February 24, 2007 Share Posted February 24, 2007 Also might want to try changing your message variable to this: $message='<html><body>'; $message = "<h1>Your Results</h1>"; $message .= include('profiles/pca' . $pcatype.'.inc.htm'); $message.='</body></html>; Quote Link to comment Share on other sites More sharing options...
ACertainTrigger Posted February 24, 2007 Author Share Posted February 24, 2007 Thanks for your help everyone, I've managed to figure it out. I needed to use ob_start() to add the contents of the file to my $message variable. Here's the working code: <?php //email the user if ($emailSend == "yes") { $headers = "From: ". $emailFrom . "\r\n" . "Reply-To: $email" . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $to = $_POST['email']; $subject = "Your Results"; //Construct the contents of the email ob_start(); ?> <p>Dear<?=$name?>,</p> <p>Many thanks for taking the test, here are your results.</p> <h1>Results for <?=$pcatype?></h1> <?php include('profiles/pca' . $pcatype.'.inc.htm');?> <p>Many thanks for taking the test</p> <?php //Get the contents of the output buffer, and assign it to $message $message = ob_get_clean(); //Send the message mail($to,$subject,$message,$headers); };?> With this, I can make the contents of an include file a part of a variable and in turn use it in an email Quote Link to comment Share on other sites More sharing options...
Yesideez Posted February 24, 2007 Share Posted February 24, 2007 Glad you sorted it, just been playing with some sample code myself and found include() does work when used like that but found what I was trying to include appeared before where I was including it - I never knew about ob_start() I just learnt something new myself Quote Link to comment Share on other sites More sharing options...
ACertainTrigger Posted February 24, 2007 Author Share Posted February 24, 2007 Glad you sorted it, just been playing with some sample code myself and found include() does work when used like that but found what I was trying to include appeared before where I was including it - I never knew about ob_start() I just learnt something new myself Same here Seems to work well! Thanks again for your help! act Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.