I was able to send HTML formatted email to my personal email no problem, but when I try to send to my hotmail account I get the following error....
myemail@hotmail.com on 4/11/2008 10:36 AM
The message contains a content type that is not supported
<xxxxxxx.company.extension #5.6.1 smtp;554 5.6.1 Body type not supported by Remote Host>
Tried to add a text/plain attached part but getting the same error. any ideas?
Here's the code on my mail handler.
Code: Select all
<?php
//Check if the required fields were sent
// Redirect back to the form if not
if (empty($_POST["sender_name"]) || empty($_POST["sender_email"])
|| empty($_POST["comment_pcbackup"]) || empty($_POST["comment_business"]))
{
//redirect back to form
header("Location: ../pcbackup200_form.php?error=not_enough_info"); //This should really be an absolute URL if you know it
exit();
}
//Copy into global variables
$fromemail = $_POST["from_email"];
$name = $_POST["sender_name"];
$email = $_POST["sender_email"];
$pcbackup = $_POST["comment_pcbackup"];
$busname = $_POST["comment_business"];
//Validate the email address using a regex (I suggest you use a better one than this!!)
if (!preg_match("/[a-zA-Z0-9_\\.-]+@[a-zA-Z0-9_\\.-]+/", $email))
{
header("Location: ../pcbackup200_form.php?error=invalid_email");
exit();
}
//Check if an attachment was uploaded
$file_path = false;
$file_name = false;
$file_type = false;
if (!empty($_FILES["attachment"]["tmp_name"]))
{
if ($_FILES["attachment"]["error"])
{
//Redirect if the upload has failed
header("Location: ../pcbackup200_form.php?error=upload_failed");
exit();
}
$file_path = $_FILES["attachment"]["tmp_name"];
$file_name = $_FILES["attachment"]["name"];
$file_type = $_FILES["attachment"]["type"];
}
//Everything looks ok, we can start Swift
require_once "../swift/Swift.php";
require_once "../swift/Swift/Connection/SMTP.php";
//Enable disk caching if we can
if (is_writable("/tmp"))
{
Swift_CacheFactory::setClassName("Swift_Cache_Disk");
Swift_Cache_Disk::setSavePath("/tmp");
}
//Create a Swift instance
$swift =& new Swift(new Swift_Connection_SMTP("localhost"));
//Create the sender from the details we've been given
$sender =& new Swift_Address($fromemail, "From Name");
//Create the recipient
$receipt =& new Swift_Address($email, $name);
$recipients =& new Swift_RecipientList();
$recipients->addTo($email, $name);
//Use addCc()
//$recipients->addCc($fromemail);
//Use addBcc()
$recipients->addBcc($fromemail);
$recipients->addBcc("myemail@business.extension");
//Create the message subject
$message =& new Swift_Message("Message Subject");
//Embedded Image link - HTML Background Image
$img =& new Swift_Message_Image(new Swift_File("../images/sheet.jpg"));
//Adding the image file to a variable
$src = $message->attach($img);
//HTML Email Body
$body =& new Swift_Message_Part("HTML Information");
$body2 =& new Swift_Message_Part("HTML Information but no HTML Codes");
//$message->attach($body, "text/html");
$message->attach($body2, "text/plain");
//If an attachment was sent, attach it
if ($file_path && $file_name && $file_type)
{
$message->attach(
new Swift_Message_Attachment(new Swift_File($file_path), $file_name, $file_type));
}
//Try sending the email
$sent = $swift->send($message, $recipients, $sender);
//Try sending the email
if ($sent)
{
header("Location: ../pcbackup200_success.php");
exit();
}
else
{
header("Location: ../pcbackup200_form.php?error=sending_failed");
exit();
}
//Disconnect from SMTP, we're done
$swift->disconnect();
?>