sam06 Posted October 13, 2008 Share Posted October 13, 2008 I managed to send an email to everyone in my database using text, but now I'm trying to send HTML. My code is: while($row = mysql_fetch_array( $result )) { // Example $HTML = '<a href='http://getfreefunnies.co.uk/click.php?id=7&username= '.$row['username'].' '><img border=0 src='http://banners.affiliatefuture.com/1068/36042.jpg'></a><p>This is an email sent by <a href="http://www.getfreefunnies.co.uk">Get FreeSweets</a> - Your username is : '.$row['username'].' </p>'; $from = "samuelhale@btinternet.com"; $to = $row['email']; $subject = "Message from Get Free Sweets"; sendHTMLemail($HTML,$from,$to,$subject); function sendHTMLemail($HTML,$from,$to,$subject) { // First we have to build our email headers // Set out "from" address $headers = "From: $from\r\n"; // Now we specify our MIME version $headers .= "MIME-Version: 1.0\r\n"; // Create a boundary so we know where to look for // the start of the data $boundary = uniqid("HTMLEMAIL"); // First we be nice and send a non-html version of our email $headers .= "Content-Type: multipart/alternative;". "boundary = $boundary\r\n\r\n"; $headers .= "This is a MIME encoded message.\r\n\r\n"; $headers .= "--$boundary\r\n". "Content-Type: text/plain; charset=ISO-8859-1\r\n". "Content-Transfer-Encoding: base64\r\n\r\n"; $headers .= chunk_split(base64_encode(strip_tags($HTML))); // Now we attach the HTML version $headers .= "--$boundary\r\n". "Content-Type: text/html; charset=ISO-8859-1\r\n". "Content-Transfer-Encoding: base64\r\n\r\n"; $headers .= chunk_split(base64_encode($HTML)); // And then send the email .... mail($to,$subject,"",$headers); } } ?> It keeps coming up with unexpected T_STRING on the line: $HTML = '<a href='http://getfreefunnies.co.uk/click.php?id=7&username= '.$row['username'].' '><img border=0 src='http://banners.affiliatefuture.com/1068/36042.jpg'></a><p>This is an email sent by <a href="http://www.getfreefunnies.co.uk">Get FreeSweets</a> - Your username is : '.$row['username'].' </p>'; Cheers, Sam. Quote Link to comment https://forums.phpfreaks.com/topic/128269-solved-email-html-form/ Share on other sites More sharing options...
trq Posted October 13, 2008 Share Posted October 13, 2008 $HTML = '<a href=\'http://getfreefunnies.co.uk/click.php?id=7&username= '.$row['username'].'\'><img border=0 src=\'http://banners.affiliatefuture.com/1068/36042.jpg\'></a><p>This is an email sent by <a href="http://www.getfreefunnies.co.uk">Get FreeSweets</a> - Your username is : '.$row['username'].' </p>'; Quote Link to comment https://forums.phpfreaks.com/topic/128269-solved-email-html-form/#findComment-664355 Share on other sites More sharing options...
sam06 Posted October 14, 2008 Author Share Posted October 14, 2008 I'm now getting Fatal error: Call to undefined function sendhtmlemail() in /home/sam06/public_html/email.php on line 19 Which is the line: sendHTMLemail($HTML,$from,$to,$subject); Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/128269-solved-email-html-form/#findComment-665056 Share on other sites More sharing options...
sam06 Posted October 15, 2008 Author Share Posted October 15, 2008 Sorry to bump- but any ideas anyone? Quote Link to comment https://forums.phpfreaks.com/topic/128269-solved-email-html-form/#findComment-666237 Share on other sites More sharing options...
Andy17 Posted October 15, 2008 Share Posted October 15, 2008 Put this sendHTMLemail($HTML,$from,$to,$subject); Below your function instead of above. Quote Link to comment https://forums.phpfreaks.com/topic/128269-solved-email-html-form/#findComment-666254 Share on other sites More sharing options...
sam06 Posted October 15, 2008 Author Share Posted October 15, 2008 Like this: function sendHTMLemail($HTML,$from,$to,$subject) sendHTMLemail($HTML,$from,$to,$subject); { It comes out with Parse error: syntax error, unexpected T_STRING, expecting '{' in /home/sam06/public_html/email.php on line 20 But when I do this: function sendHTMLemail($HTML,$from,$to,$subject) { sendHTMLemail($HTML,$from,$to,$subject); It comes out with Fatal error: Cannot redeclare sendhtmlemail() (previously declared in /home/sam06/public_html/email.php:19) in /home/sam06/public_html/email.php on line 19 Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/128269-solved-email-html-form/#findComment-666362 Share on other sites More sharing options...
Andy17 Posted October 15, 2008 Share Posted October 15, 2008 I didn't mean inside your function. Try to copy the code below: <?php function sendHTMLemail($HTML,$from,$to,$subject) { // First we have to build our email headers // Set out "from" address $headers = "From: $from\r\n"; // Now we specify our MIME version $headers .= "MIME-Version: 1.0\r\n"; // Create a boundary so we know where to look for // the start of the data $boundary = uniqid("HTMLEMAIL"); // First we be nice and send a non-html version of our email $headers .= "Content-Type: multipart/alternative;". "boundary = $boundary\r\n\r\n"; $headers .= "This is a MIME encoded message.\r\n\r\n"; $headers .= "--$boundary\r\n". "Content-Type: text/plain; charset=ISO-8859-1\r\n". "Content-Transfer-Encoding: base64\r\n\r\n"; $headers .= chunk_split(base64_encode(strip_tags($HTML))); // Now we attach the HTML version $headers .= "--$boundary\r\n". "Content-Type: text/html; charset=ISO-8859-1\r\n". "Content-Transfer-Encoding: base64\r\n\r\n"; $headers .= chunk_split(base64_encode($HTML)); // And then send the email .... mail($to,$subject,"",$headers); } while($row = mysql_fetch_array( $result )) { // Example $HTML = '<a href=\'http://getfreefunnies.co.uk/click.php?id=7&username= '.$row['username'].'\'><img border=0 src=\'http://banners.affiliatefuture.com/1068/36042.jpg\'></a><p>This is an email sent by <a href="http://www.getfreefunnies.co.uk">Get FreeSweets</a> - Your username is : '.$row['username'].' </p>'; $from = "samuelhale@btinternet.com"; $to = $row['email']; $subject = "Message from Get Free Sweets"; sendHTMLemail($HTML,$from,$to,$subject); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/128269-solved-email-html-form/#findComment-666571 Share on other sites More sharing options...
trq Posted October 16, 2008 Share Posted October 16, 2008 Functions do not need to be declared prior to calling them in php (as long as they are in scope), the problem is that your redeclaring the function with each iteration of your loop. You can only have one function called foo() declared within scope at any one time. Quote Link to comment https://forums.phpfreaks.com/topic/128269-solved-email-html-form/#findComment-666706 Share on other sites More sharing options...
sam06 Posted October 16, 2008 Author Share Posted October 16, 2008 Oh I get it now, it defines the function, then carries it out in the loop. That's brilliant, thank you!!!!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/128269-solved-email-html-form/#findComment-666864 Share on other sites More sharing options...
Andy17 Posted October 16, 2008 Share Posted October 16, 2008 Functions do not need to be declared prior to calling them in php (as long as they are in scope) Ah, actually I thought of that. I just remember having some problems with it back when I was worse than I am now and I don't remember how I fixed it. Quote Link to comment https://forums.phpfreaks.com/topic/128269-solved-email-html-form/#findComment-666911 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.