0

嗨,我的邮件工作正常,但我不知道如何发送 html 格式的邮件,因为我使用的是 pear 邮件!这里我使用代码使用 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>';
    }
}
?>
4

1 回答 1

1

您设置的标题不正确。例如,您正在做类似的事情

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

应该只是

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

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

于 2013-10-10T14:19:01.677 回答