php pear mail无法发送html格式的邮件

时间:2013-10-10 14:10:20

标签: php html email

您好,我的邮件工作正常,但我不知道如何发送html格式的邮件,因为我正在使用梨邮件!这里我使用代码发送邮件使用PHP,首先调用mail.php和mime .PHP。 $提到要发送邮件的邮件ID,要发送邮件,您需要指定电子邮件ID和发件人邮件的电子邮件密码。

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


require_once 'Mail/mimePart.php';

    $from = "you@localhost.com";

    $to = "you@gmail.com";//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="you@gmail.com";// 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>';
    }
}
?>

1 个答案:

答案 0 :(得分:1)

您正在错误地设置标题。例如,你正在做像

这样的事情
'Contenttype'=> 'Content-type: text/html';

应该只是

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

PEAR :: Mail是一个非常糟糕的包。你应该切换到更好的东西,比如PHPMailer或Swiftmailer。