SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2007
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Your advice please - sending emails via php

    Hi Guys,

    Iíve written a script which sends a html email out. Now it works well, but I have a couple of issues.

    The email sends fine in clients like Outlook Express and in hotmail, but in other clients such as webmail clients such as Thunderbird and Googlemail it:

    1) Does not deliver the message as HTML
    2) Marks the email as spam.

    So my question is, is there anything different I could to do prevent these measures happening? Or is it simply best to send a plain text email?

    Thanks

    Chris

    PHP Code:
    <?php


    // End the connection to the database  

    $query_one "select * FROM `email_alerts` Order By alert_id DESC LIMIT 1"

    $result mysql_query($query_one)  OR die(mysql_error()); 
    while (
    $row mysql_fetch_array($result)) { 
      
    $addy .= stripslashes($row['email_subject']);
      
    $messagebody .= "<font style=\"font-family:tahoma, arial, verdana;font-size:10pt\"><b>** This is an automated message - please do not reply **<br /> Please find an email alert below:</b></font><br /><br />";   
    $messagebody .= "
    <table width=\"100%\" border=\"0\">
      <tr>
        <td valign=\"top\">
    <table border=\"0\" align=\"right\" cellpadding=\"6\" cellpadding=\"6\">
            <tr>
              <td valign=\"top\"><img src=\"http://www.awebsitedomain.co.uk/history/images/logo.jpg\" alt=\"Alt Tag Here\" class=\"no_border\"></td>
            </tr>
          </table>
          <font style=\"font-family:tahoma, arial, verdana;font-size:10pt\">"
    nl2br($row['email_text']) ."</font>
          </td>
      </tr>
    </table>"
    ;


    $query_two "SELECT your_name, your_email FROM `email_addresses`"
    $result mysql_query($query_two)  OR die(mysql_error());

    $number_of_results mysql_num_rows($result);

    If (
    mysql_num_rows($result) > 0) {
      echo 
    "We have send the  email out to <b>".$number_of_results."</b> registered users<br />";
    }
    else {
      
    $row mysql_fetch_array$result );
      echo 
    "Nobody has registered for email alerts";
    }

    while (
    $row mysql_fetch_array($result)) { 

    $headers  "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers .="From: theaddress@thewebsitedomain.net\r\nContent-type: text/html";

    $lines "<br />-------------------------------------------------------------------------------------------------------------<br />";
    $your_name "<font style=\"font-family:tahoma, arial, verdana;font-size:10pt\">Dear "$row['your_name'] ."<br /><br /></font>";
    $unsubscribe "<font style=\"font-family:tahoma, arial, verdana;font-size:10pt\">To unsubscribe from this email alert please visit the link below:<br /></font>";
    $messagelink "<font style=\"font-family:tahoma, arial, verdana;font-size:10pt\"><a href='http://www.the-url-to-unsubscribe-when-site-live.co.uk.php?email="$row['your_email'] ."'>http://www.the-url-to-unsubscribe-when-site-live.co.uk.php?email="$row['your_email'] ."</a><br /><br /></font>";

    $message $your_name.$messagebody.$lines.$unsubscribe.$messagelink;

      
    mail($row['your_email'], $addy$message$headers); 


    ?>

  2. #2
    Working on it... Contrid's Avatar
    Join Date
    Apr 2006
    Location
    Online
    Posts
    955
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I would recommend that you use SwiftMailer or phpMailer classes, since it has many additional features and advantages. One of the main advantages (from my personal experience) is that mail sent by these classes are not likely to end up in the spam box because of the additional headers they insert upon processing the email.
    And so I got lost in code...completely asphyxiated by it...

    Premium WordPress plugins - Tribulant Software

  3. #3
    Working on it... Contrid's Avatar
    Join Date
    Apr 2006
    Location
    Online
    Posts
    955
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Also...I see a problem in your first while() loop.
    You are appending data to the $addy and $messagebody variables upon each loop.
    If you had 500 records in the database, the email would consist of the $messagebody repeated 500 times.
    And so I got lost in code...completely asphyxiated by it...

    Premium WordPress plugins - Tribulant Software

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sometimes the new line issues matters for proper HTML body texts as i have faced before. When i was testing in Windows OS it needs \r\n and if you are using Linux server again then it needs to \n only. So will you give a try your header like this?
    PHP Code:
    $headers  "MIME-Version: 1.0\n"
    $headers .= "Content-type: text/html; charset=iso-8859-1\n"
    $headers .="From: theaddress@thewebsitedomain.net\nContent-type: text/html\n"
    I assume that you are in Linux server.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •