Body type not supported by Remote Host [SOLVED]

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
User avatar
eymorais
Forum Newbie
Posts: 14
Joined: Fri Apr 11, 2008 8:38 am
Location: Moncton NB Canada

Body type not supported by Remote Host [SOLVED]

Post by eymorais »

Need a bit of help.

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();
 
 
 
?>
Last edited by eymorais on Mon Apr 14, 2008 11:56 am, edited 1 time in total.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Body type not supported by Remote Host

Post by Chris Corbyn »

Code: Select all

$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");
Should actually be:

Code: Select all

$body =& new Swift_Message_Part("HTML Information", "text/html");
 
$body2 =& new Swift_Message_Part("HTML Information but no HTML Codes", "text/plain");
 
//$message->attach($body);
$message->attach($body2);
User avatar
eymorais
Forum Newbie
Posts: 14
Joined: Fri Apr 11, 2008 8:38 am
Location: Moncton NB Canada

Re: Body type not supported by Remote Host

Post by eymorais »

Works with just a basic text entry with the text/html mime, but as soon as I put HTML formating it craps on me...

I've tried removing my <head>, <style> and <body> entries but it still give me an unrecognized body error.

Any ideas?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Body type not supported by Remote Host

Post by Chris Corbyn »

It doesn't say it's not recognized, it says it's not supported ;) I find it hard to believe any server admin would be crazy enough to block HTML and/or multipart emails though. The code you posted looks correct to me if you made those amendments.
User avatar
eymorais
Forum Newbie
Posts: 14
Joined: Fri Apr 11, 2008 8:38 am
Location: Moncton NB Canada

Re: Body type not supported by Remote Host

Post by eymorais »

Had to change my smtp server after all. Problem now resolved.
Post Reply