Jump to content

[SOLVED] Email HTML Form


sam06

Recommended Posts

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         = "[email protected]";
$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.

Link to comment
https://forums.phpfreaks.com/topic/128269-solved-email-html-form/
Share on other sites

$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>';

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?

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         = "[email protected]";
$to           = $row['email'];
$subject = "Message from Get Free Sweets";

sendHTMLemail($HTML,$from,$to,$subject);

}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.