2013-10-10 65 views
0

嗨在這裏我的郵件工作正常,但我不知道如何發送一個HTML格式的郵件,因爲我使用梨郵件!在這裏我使用的代碼發送郵件使用PHP ,首先調用mail.php和mime.php。 $要提及您要發送郵件的郵件編號,發送郵件時需要指定發件人郵件的電子郵件編號和密碼。php梨郵件不能發送HTML格式郵件

<?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 [email protected] 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

您正在設置您的標題不正確。 e.g你正在做的東西像

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

這應該只是

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

PEAR ::郵件是一個可怕的蹩腳包。你應該改用更好的東西,比如PHPMailer或Swiftmailer。

+0

您的PEAR評論的原因是什麼? –