Gå til innhold

Hvordan sende HTML epost? (Nyhetsbrev)


Anbefalte innlegg

Jeg har laget et nyhetsbrev, til hjemmesiden min. Men jeg får ikke til å sende det som HTML slik at man får disse fine brevene med bilder i.

 

Nyhetsbrevet

 

Her er da slik det ser ut. Jeg har brukt bare tables på layoutet for har lest at det er det som er mest venlig i forhold til epostlesere.

Problemet er at jeg ikke får sendt det som HTML epost. Er det noen som kan hjelpe meg?

 

Jeg bruker et script som registrerer alle nye abonenter, det er ganske basic, og det samme bruker jeg for å sende eposten.

 

Her er koden for selve brevet:

 

<html>
<head>
<title>nyhetsbrev</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- ImageReady Slices (nyhetsbrev.psd) -->
<table id="Table_01" width="498" height="600" border="0" cellpadding="0" cellspacing="0" style="margin:0 auto;">
<tr>
 <td colspan="3">
 	<img src="http://www.drilltropp2006.com/newsletter/images/nyhetsbrev_01.gif" width="498" height="175" alt=""></td>
</tr>

<tr>
 <td>
 	<img src="http://www.drilltropp2006.com/newsletter/images/nyhetsbrev_02.gif" width="20" height="379" alt=""></td>
 <td background="http://www.drilltropp2006.com/newsletter/images/nyhetsbrev_03.gif" width="460" height="379" align="justify">
 <p style="color:#CCCCCC; font-size:16px; font-weight:bold; border-bottom:solid 1px;">Dette er da overskriften da.</p>
 <p style="color:#CCCCCC; text-align:justify;">Funker detta da? Funker detta da? Funker detta da?Funker detta da?Funker detta da?Funker detta da?Funker detta da?Funker detta da?Funker detta da?Funker detta da?Funker detta da?Funker detta da?Funker detta da?Funker detta da?Funker detta da?Funker detta da?Funker detta da?</p>
 <br />
 <br />

 <br />
 <br />
 <br />
 <br />
 <br />
 <br />
 <br />
 <br />
 
 	</td>

 <td>
 	<img src="http://www.drilltropp2006.com/newsletter/images/nyhetsbrev_04.gif" width="18" height="379" alt=""></td>
</tr>
<tr>
 <td colspan="3">
 	<img src="http://www.drilltropp2006.com/newsletter/images/nyhetsbrev_05.gif" width="498" height="45" alt=""></td>
</tr>
<tr>
 <td colspan="3">

 	<img src="http://www.drilltropp2006.com/newsletter/images/nyhetsbrev_06.gif" width="498" height="1" alt=""></td>
</tr>
</table>
<!-- End ImageReady Slices -->
</body>
</html>

 

Her er koden for nyhetsbrevscriptet:

 

<?php

Requirements:
PHP
SMTP


##########################
# VARIABLES - EDIT THESE #
##########################

// What do you want the administrator password to be (to send emails)?
// Enter the password into the form to add an e-mail address and it will give you a form to send email to the users
$adminpass = "";

// What do you want the From address for emails sent from the script to be?
$fromemail = "";

// What's the name of the file emails will be stored in?
$file = "newsletter/emails.txt";

// How many e-mail addresses should the file be limited to?
// Set to 0 for unlimited
$limit = "0";

############################
# BE CAREFUL EDITING BELOW #
############################

// Create function to limit number of addresses
function checklimit ($limit) {

   // Get filename and limit
   global $file;

   // Find number of lines in file
   $lines = file($file);
   $num_lines = count($lines);

   // Error if limit reached
   if ($limit == "0") {
       $limitreached = "NO";
   } elseif ($num_lines >= $limit) {
       $limitreached = "YES";
   } else {
       $limitreached = "NO";
   }

   // Return error
   return $limitreached;
}

// Process the form to send email if submitted
if (($_GET['do'] == "send") && ($_POST['password'] == $adminpass) && (isset($_POST['subject'])) && (isset($_POST['body']))) {

   // Open the list
   $fh = fopen($file, "a+");
   if ($fh) {

       // Get the contents of the list
       $data = file($file);

       // Pick out each email in the list
       for ($n = 0; $n < count($data); $n++) {
           $line = explode("\n", $data[$n]);



           // Send an email to each individual address in the list
           mail($line[0], $_POST['subject'], $_POST['body'], "From: $fromemail");
       }

       // Success message
       $msg = "The e-mail was sent to all addresses on the list.";

   // Error if list can't be opened
   } else {
       $error = "Sorry, the mailing list cannot be accessed - please try again later.";
   }

   // Close the list
   fclose($fh);

// Process the form to add an email if submitted
} elseif (($_GET['do'] == "add") && (isset($_POST['email']))) {

   // Replace the < and > in e-mail address for showing on HTML page
   $lefttag = "<";
   $righttag = ">";
   $EmailFix = str_replace("<", $lefttag, $_POST[email]);
   $EmailFix = str_replace(">", $righttag, $EmailFix);

   // Check if admin
   if ($_POST['email'] == $adminpass) {

       // Show form to send email
       echo "<form method=\"POST\" action=\"" . $_SERVER['PHP_SELF'] . "?do=send\">\n";
       echo "<input type=\"hidden\" name=\"password\" value=\"$_POST[email]\">\n";
       echo "Subject:<br>\n<input type=\"text\" name=\"subject\"><br>\n";
       echo "Body:<br>\n<textarea name=\"body\" cols=\"50\" rows=\"20\"></textarea><br>\n";
       echo "<input type=\"submit\" value=\"Send\">\n"; ?>
 <br />
 <br />
<?php
       // End the script
       

   // Check address limit
   } elseif (checklimit($limit) == "YES") {
       $error = "Sorry, the limit of e-mail addresses allowed has been reached and new addresses cannot be added at this time.";

   // Check the email
   } elseif (!eregi("^([a-z ])*(<)?[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}(>)?$", $_POST['email'])) {
       $error = "Please enter a valid e-mail address.";

   // Add the email if it doesn't already exist
   } else {

       // Open the list
       $fh = fopen($file, "a");
       if ($fh) {

           // Get the contents of the list
           $data = file($file);

           // Compare each email in list with the one being entered
           for ($n = 0; $n < count($data); $n++) {
               $line = explode("\n", $data[$n]);

               // Error if email being entered matches one in the list
               if (eregi("^(\\$_POST[email])$", $line[0])) {
                   $emailexists = "yes";
                   $error = "That e-mail address $EmailFix is already in the list.";
               }
           }

       // Error if list can't be opened
       } else {
           $emailexists = "yes";
           $error = "Sorry, the mailing list cannot be accessed - please try again later.";
       }

       // Write to file if email doesn't already exist
       if ($emailexists != "yes") {

           // Write to the list and give success message
           fwrite($fh, "$_POST[email]\n");
           $msg = "Your e-mail address $EmailFix was successfully added to the list!";
       }

       // Close the list
       fclose($fh);
   }
}

// Show any errors encountered
if (isset($error)) {
   echo "<font color=\"red\"><b>" . $error . "</b></font><br><br>\n";

// Show success message if there was one and end script, and no errors were encountered
} elseif (isset($msg)) {
   echo "<b>" . $msg . "</b>\n";
   
}

?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>?do=add">
<input style="width:125px" type="password" name="email">
<input type="submit" value="log in">
</form>

Lenke til kommentar
Videoannonse
Annonse

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
  • Hvem er aktive   0 medlemmer

    • Ingen innloggede medlemmer aktive
×
×
  • Opprett ny...