user2207431
user2207431

Reputation: 1

php pear mail cant send the html formatted mail

Hi here my mail is working fine, but i dont know how to send a html formatted mail, because i am using pear mail!here i am using the code to send mail using php , first calling the mail.php and mime.php. $to mention which mail id you want to send a mail, to send a mail you need specify email id and password of email which is the sender mail.

<?php
if(isset($_POST['submit']))
{
require_once "Mail.php";//calling mail function


require_once 'Mail/mimePart.php';

    $from = "[email protected]";

    $to = "[email protected]";//your mail id

    $CompanyName = $_POST['CompanyName'];

    $mobile = $_POST['mobile'];


    $email  = $_POST['email'];

    $paddress = $_POST['paddress'];

    $subject = 'MOSONS Group';
    $message = 'PersonName: ' .$CompanyName. "\n";

    $message .= 'Mobile: ' .$mobile. "\n";

    $message .= 'Email: ' .$email. "\n";

    $message .= 'Message: ' .$paddress. "\n";

    $host="ssl://smtp.gmail.com";

    $port="465";

    $username="[email protected]";// your email id 

    $password="yourpassword"; //password

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

    $type= "Content-type: text/html\r\n";

    $headers = array ('From' => $from,'To' => $to ,'Subject'=> 
$subject,'Mime'=> $mime,'Contenttype'=> $type);


    $smtp =@ Mail::factory('smtp',array ('host'=>$host,'port'=>$port,'auth'=>true,'username'=>$username,'password'=>$password));


    $mail = @$smtp-> send($to,$headers,$message);


    if(@PEAR::isError($mail)){
        echo ("<p>" .$mail->getmessage(). "</p>");
    }
    else
    {
        echo '<script type="text/javascript">alert("Thank You for Contacting us, our team will get in touch with you soon.!"); </script>';
    }
}
?>

Upvotes: 0

Views: 461

Answers (1)

Marc B
Marc B

Reputation: 360572

You are setting your headers incorrectly. e.g you're doing stuff like

'Contenttype'=> 'Content-type: text/html';

It should be just

'Content-Type' => 'text/html'

PEAR::Mail is a horribly crappy package. You should switch to something better, like PHPMailer or Swiftmailer.

Upvotes: 1

Related Questions