Jump to content

Recommended Posts

Hello All,

 

A quick questionthat I'm sure has an easy solution. I designed both an html and text based email notification for a client, with the default set to deliver html emails. Some people are having trouble receiving them, so i need to add a "Trouble Viewing This Email? CLICK HERE" link at the top before the html email, but I cannot figure out how to do it. This is my code:

 

$to = $emails;

 

$subject = 'Luggage Repair Receipt';

 

$headers = "From: repairs@mysite.com\r\n";

$headers .= "MIME-Version: 1.0\r\n";

$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

 

$message = '<html><body>';

$message = '<p><a href="http://www.mysite.com/mysite/viewrepair3.php?usersearch=' . $repair_id . '&name=' . $last_name . '&submit=Submit">IF YOU CANNOT READ THIS EMAIL CLICK HERE</a></p>';

$message .= '<img src="http://www.mysite.com/mysite/header2.gif" alt="Repair Notification" />';

$message .= "<p>" . $first_name . ",</p>";

$message .= "<p>Thank you for stopping by. This emails contains information about your recent repair.</p>";

$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';

$message .= "<tr style='background: #eee;'><td><strong>Your repair receipt number is:</strong> </td><td><strong>" . $repair_id . "</strong></td></tr>";

$message .= "<tr><td><strong>Pick Up Date:</strong> </td><td>" . $ready_date2 . "</td></tr>";

$message .= "<tr><td><strong>Brand:</strong> </td><td>" . $manufacturer . "</td></tr>";

$message .= "<tr><td><strong>Item Description:</strong> </td><td>" . $item_description . "</td></tr>";

$message .= "<tr><td><strong>Color:</strong> </td><td>" . $color . "</td></tr>";

$message .= "<tr><td><strong>Exterior:</strong> </td><td>" . $exterior_construction . "</td></tr>";

$message .= "<tr><td><strong>Repair Description:</strong> </td><td>" . $repair_description . "</td></tr>";

$message .= "<tr><td><strong>Under Warranty:</strong> </td><td>" . $warranty . "</td></tr>";

$message .= "<tr><td><strong>Total Charges:</strong> </td><td>$" . $total_amount . "</td></tr>";

$message .= "<tr><td><strong>Status:</strong> </td><td>Scheduled for repair</td></tr>";

$message .= "</table>";

$message .= "<p>For more information please visit www.mysite.com/repairstatus.html <br /><br /><br /><strong>Luggage Company</strong> <br /></p>";

$message .= "<p>SW 12th Ave. <br />New York, NY 10015 <br />ph: (555) 222-1212 <br />fax: (555) 222-1212 <br />Toll-Free:(555)222-1212 <br />www.mysite.com <br /> <br /><strong>Hours</strong> <br /> <br />Monday thru Friday: 8:30 am ~ 6:00 pm <br />Saturday: 9:00 am ~ 5:00 pm <br />Sunday: By Appointment Only</p>";

$message .= '<img src="http://www.mysite.com/mysite/footer.gif" alt="Ready For Pick Up Notification 2" />';

$message .= "</body></html>";

 

mail($to, $subject, $message, $headers);

 

I added something I thought would work, but obviously I skipped a logic step- can somebody help?

Link to comment
https://forums.phpfreaks.com/topic/172626-html-email-troubles-viewing/
Share on other sites

You're exactly right. I think the multipart email is the way to go, but im not sure how to do it in this application. I believe it would change the content type to text/multipart, but how would the link be added above and included in the mail() command. Does anybody have an example?

Here's a sample

 

from what you have posted I believe you shouldn't have any problems integrating it :)

$notice_text = "This is a multi-part message in MIME format.";
$plain_text = "This is a plain text email.\r\nIt is very cool.";
$html_text = "<html><body>This is an <b style='color:purple'>HTML</b> text email.\r\nIt is very cool.</body></html>";

$semi_rand = md5(time());
$mime_boundary = "==MULTIPART_BOUNDARY_$semi_rand";
$mime_boundary_header = "\"$mime_boundary\"";

$to = "Me <me@me.com>";
$bcc = "You <you@you.com>, Them <them@them.com>";
$from = "Me.com <me@me.com>";
$subject = "My Email";

$body = "$notice_text

--$mime_boundary
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

$plain_text

--$mime_boundary
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

$html_text

--$mime_boundary--";

if (@mail($to, $subject, $body,
    "From: " . $from . "\n\r" .
    "bcc: " . $bcc . "\n\r" .
    "MIME-Version: 1.0\n\r" .
    "Content-Type: multipart/alternative;\n\r" .
    "     boundary=" . $mime_boundary_header))
{
    echo "Email sent successfully.";
}else{
    echo "Email NOT sent successfully!";
}

Ok, so I think this will work- does it look correct before I launch it or did I miss something. Again, I'm a little unfamiliar with this format. Again, I'm trying to have the html email display, but have a link above it that will display in plain text with a hyper link to an external site where the email contents can be viewed.

 

$notice_text = "IF YOU CANNOT READ THIS EMAIL FOLLOW THIS LINK: www.mysite.com/repairstatus.html";

 

$plain_text = "$first_name,\n\n" .

      "Thank you for stopping by Luggage Shop. This emails contains information about your recent repair\n\n" .

      "Your repair receipt number is: $repair_id\n\n" .

      "The details of your order are as follows:\n\n" .

      "Pick Up Date: $ready_date2\n" .

      "Brand: $manufacturer\n" .

      "Item Description: $item_description\n" .

      "Color: $color\n" .

      "Exterior: $exterior_construction\n" .

      "Repair Description: $repair_description\n" .

      "Estimated Charges: $estimated_charges\n\n" .

      "For more information please visit www.mysite.com/repairstatus.html\n\n" .

      "We appreciate your business!\n\n" .

      "Luggage Company\n\n" .

      "www.mysite.com";

 

$html_text = '<html><body>';

$html_text .= '<img src="http://www.mysite.com/header2.gif" alt="Repair Notification" />';

$html_text .= "<p>" . $first_name . ",</p>";

$html_text .= "<p>Thank you for stopping by Luggage Store. This emails contains information about your recent repair.</p>";

$html_text .= '<table rules="all" style="border-color: #666;" cellpadding="10">';

$html_text .= "<tr style='background: #eee;'><td><strong>Your repair receipt number is:</strong> </td><td><strong>" . $repair_id . "</strong></td></tr>";

$html_text .= "<tr><td><strong>Pick Up Date:</strong> </td><td>" . $ready_date2 . "</td></tr>";

$html_text .= "<tr><td><strong>Brand:</strong> </td><td>" . $manufacturer . "</td></tr>";

$html_text .= "<tr><td><strong>Item Description:</strong> </td><td>" . $item_description . "</td></tr>";

$html_text .= "<tr><td><strong>Color:</strong> </td><td>" . $color . "</td></tr>";

$html_text .= "<tr><td><strong>Exterior:</strong> </td><td>" . $exterior_construction . "</td></tr>";

$html_text .= "<tr><td><strong>Repair Description:</strong> </td><td>" . $repair_description . "</td></tr>";

$html_text .= "<tr><td><strong>Under Warranty:</strong> </td><td>" . $warranty . "</td></tr>";

$html_text .= "<tr><td><strong>Total Charges:</strong> </td><td>$" . $total_amount . "</td></tr>";

$html_text .= "<tr><td><strong>Status:</strong> </td><td>Scheduled for repair</td></tr>";

$html_text .= "</table>";

$html_text .= "<p>For more information please visit www.mysite.com/repairstatus.html <br /><br /><br /><strong>Luggage Company</strong> <br /></p>";

$html_text .= '<img src="http://www.mysite.com/footer.gif" alt="Ready For Pick Up Notification 2" />';

$html_text .= "</body></html>";

 

$semi_rand = md5(time());

$mime_boundary = "==MULTIPART_BOUNDARY_$semi_rand";

$mime_boundary_header = "\"$mime_boundary\"";

 

$to = "Me <myemail@mysite.com>";

$bcc = "Me <myemail@mysite.com>";

$from = "Luggage.com <repairs@mysite.com>";

$subject = "Luggage Repair Receipt";

 

$body = "$notice_text

 

--$mime_boundary

Content-Type: text/plain; charset=us-ascii

Content-Transfer-Encoding: 7bit

 

$plain_text

 

--$mime_boundary

Content-Type: text/html; charset=us-ascii

Content-Transfer-Encoding: 7bit

 

$html_text

 

--$mime_boundary--";

 

if (@mail($to, $subject, $body,

    "From: " . $from . "\n\r" .

    "bcc: " . $bcc . "\n\r" .

    "MIME-Version: 1.0\n\r" .

    "Content-Type: multipart/alternative;\n\r" .

    "    boundary=" . $mime_boundary_header))

{

    echo "Email sent successfully.";

}else{

    echo "Email NOT sent successfully!";

 

THANKS IN ADVANCE!!

remove the $notice_text from your code and add the text directly into the plain text

$plain_text = "$first_name,\n\n" .
       "IF YOU CANNOT READ THIS EMAIL FOLLOW THIS LINK: www.mysite.com/repairstatus.html\n".
       "Thank you for stopping by Luggage Shop. This emails contains information about your recent repair\n\n" .

Damn. I just cannot seem to make this work. I'm using PHP5 and MySQL 5. This is the code I used, its now simplified. Could it be the mail format or perhaps is it missing some ;'s inside the $body?

 

$plain_text = "IF YOU CANNOT READ THIS EMAIL FOLLOW THIS LINK: www.luggagesite.com/repairstatus.html";

 

$html_text = '<html><body>';

$html_text .= '<img src="http://www.mysite.com/header2.gif" alt="Repair Notification" />';

$html_text .= "<p>" . $first_name . ",</p>";

$html_text .= "<p>Thank you for stopping by Luggage Store. This emails contains information about your recent repair.</p>";

$html_text .= '<table rules="all" style="border-color: #666;" cellpadding="10">';

$html_text .= "<tr style='background: #eee;'><td><strong>Your repair receipt number is:</strong> </td><td><strong>" . $repair_id . "</strong></td></tr>";

$html_text .= "<tr><td><strong>Pick Up Date:</strong> </td><td>" . $ready_date2 . "</td></tr>";

$html_text .= "<tr><td><strong>Brand:</strong> </td><td>" . $manufacturer . "</td></tr>";

$html_text .= "<tr><td><strong>Item Description:</strong> </td><td>" . $item_description . "</td></tr>";

$html_text .= "<tr><td><strong>Color:</strong> </td><td>" . $color . "</td></tr>";

$html_text .= "<tr><td><strong>Exterior:</strong> </td><td>" . $exterior_construction . "</td></tr>";

$html_text .= "<tr><td><strong>Repair Description:</strong> </td><td>" . $repair_description . "</td></tr>";

$html_text .= "<tr><td><strong>Under Warranty:</strong> </td><td>" . $warranty . "</td></tr>";

$html_text .= "<tr><td><strong>Total Charges:</strong> </td><td>$" . $total_amount . "</td></tr>";

$html_text .= "<tr><td><strong>Status:</strong> </td><td>Scheduled for repair</td></tr>";

$html_text .= "</table>";

$html_text .= '<img src="http://www.mysite.com/footer.gif" alt="Ready For Pick Up Notification 2" />';

$html_text .= "</body></html>";

 

$semi_rand = md5(time());

$mime_boundary = "==MULTIPART_BOUNDARY_$semi_rand";

$mime_boundary_header = "\"$mime_boundary\"";

 

$to = "you@yoursite.com";

$bcc = "me@mysite.com";

$from = "me@mysite.com";

$subject = "Luggage Repair Receipt";

 

$body = "--$mime_boundary

Content-Type: text/plain; charset=us-ascii

Content-Transfer-Encoding: 7bit

 

$plain_text

 

--$mime_boundary

Content-Type: text/html; charset=us-ascii

Content-Transfer-Encoding: 7bit

 

$html_text

 

--$mime_boundary--";

 

if (@mail($to, $subject, $body,

    "From: " . $from . "\n\r" .

    "bcc: " . $bcc . "\n\r" .

    "MIME-Version: 1.0\n\r" .

    "Content-Type: multipart/alternative;\n\r" .

    "    boundary=" . $mime_boundary_header))

{

    echo "Email sent successfully.";

}else{

    echo "Email NOT sent successfully!";

}

The above produced:

 

bcc: me@mysite.com

 

MIME-Version: 1.0

 

Content-Type: multipart/alternative;

 

    boundary="==MULTIPART_BOUNDARY_8e30d08b7a428e9be1d53262370a565c"

 

--==MULTIPART_BOUNDARY_8e30d08b7a428e9be1d53262370a565c

Content-Type: text/plain; charset=us-ascii

Content-Transfer-Encoding: 7bit

 

IF YOU CANNOT READ THIS EMAIL FOLLOW THIS LINK: www.mysite.com/repairstatus.html

 

--==MULTIPART_BOUNDARY_8e30d08b7a428e9be1d53262370a565c

Content-Type: text/html; charset=us-ascii

Content-Transfer-Encoding: 7bit

 

<html><body><img src="http://www.mysite.com/header2.gif" alt="Repair Notification" /><p>John,</p><p>Thank you for stopping by Luggage Store. This emails contains information about your recent repair.</p><table rules="all" style="border-color: #666;" cellpadding="10"><tr style='background: #eee;'><td><strong>Your repair receipt number is:</strong> </td><td><strong>418</strong></td></tr><tr><td><strong>Pick Up Date:</strong> </td><td>09-30-2009</td></tr><tr><td><strong>Brand:</strong> </td><td>Bosca</td></tr><tr><td><strong>Item Description:</strong> </td><td>Attache Case</td></tr><tr><td><strong>Color:</strong> </td><td>Black</td></tr><tr><td><strong>Exterior:</strong> </td><td>Fabric</td></tr><tr><td><strong>Repair Description:</strong> </td><td>Test of timestamp</td></tr><tr><td><strong>Under Warranty:</strong> </td><td>No</td></tr><tr><td><strong>Total Charges:</strong> </td><td>$20.00</td></tr><tr><td><strong>Status:</strong> </td><td>Scheduled for repai

r</td></tr></table><p>For more information please visit www.mysite.com/repairstatus.html <br /><br /><img src="http://www.sunwellmedia.com/footer.gif" alt="Ready For Pick Up Notification 2" /></body></html>

 

--==MULTIPART_BOUNDARY_8e30d08b7a428e9be1d53262370a565c--

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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