尝试以HTML格式发送时未发送电子邮件

时间:2013-09-10 16:11:36

标签: email

我可以发送纯文本但不能发送HTML .. 请协助为什么邮件没有收到.. THX提前:) 以下是代码:

  $mailBody ='<table width="100%" >
  <tr>
  <td>   
            <img src="MailerImages/img_logo.gif"  alt="UrMint.com"/>
            <h1 style="font:bold 20px tahoma; color:#808080;">Hi #USERNAME,</h1>
            <p style="font:13px tahoma; color:#666666; line-height:25px;">


             Your password for xyzacccount associated with mobile no password #MOBNO is : <strong style="color:#e65786;">#PASSWORD</strong>
            <br />
            If you didn\'t request a new password, let us know immediately.  
            <br />
            This message was sent from xyz.com at your request.
            </p>

            <strong style="font:bold 13px tahoma; color:#666666;  line-height:25px;">
            Happy Learning ,
            <br />
            The <span style="color:#42b1d6;">Ur</span><span style="color:#e65786;">urMint</span> Team
            </strong>
        </table>    

            ';
            echo  $mailBody;
        SendEMail_fun('xyz@gmail.com', $mailBody,'sub','xyzsender','xyz@rediffmail.com');   

函数SendEMail_fun($ strEmailTo,$ strEmailBody,$ strSubject,$ SenderName ='',$ SenderEmail ='')
        {
            全球$ SwiftMessage;             $ SenderName = $ SenderName&lt;&gt; ? '' $发送者姓名: “support@xyz.com”;

        $SenderEmail    =   $SenderEmail <> ''?$SenderEmail:"support@xyz.com";

        $email_from_name = $SenderName." <".$SenderEmail.">";


        $email_from_mail = $SenderEmail;
        $email_to_bcc= "";
        $email_to= $strEmailTo;
        $email_subject= $strSubject;

        $emailbody =$strEmailBody;

        try
        {  

            require_once ("lib/Swift.php");


            $smtp = new Swift_Connection_SMTP("localhost", 25);


            $swift = new Swift($smtp);

            $message = new Swift_Message($email_subject, $emailbody, "text/html");
            $message->setFrom($email_from_name);
            $message->setReplyTo($email_from_mail);
            $message->setBcc($email_to_bcc);


            if ($swift->send($message, $email_to, $email_from_mail))
            {
                //echo "Message sent";
                 echo  $SwiftMessage = 'Message Sent';
                return true;
            }
            else
            {
                //echo "Message failed to send";
                 echo  $SwiftMessage = 'Message failed to send';
                return false;
            }
            $swift->disconnect();
            return true;
        }
        catch (Swift_ConnectionException $e)
        {
            //          echo "There was a problem communicating with SMTP: " . $e->getMessage();
             echo  $SwiftMessage = "There was a problem communicating with SMTP: " . $e->getMessage();
            return false;
        } 
        catch (Swift_Message_MimeException $e)
        {
            //    echo "There was an unexpected problem building the email:" . $e->getMessage();
            echo  $SwiftMessage = "There was an unexpected problem building the email:" . $e->getMessage();
            return false;
        }

    }

1 个答案:

答案 0 :(得分:0)

我不确定你的确切原因是什么。我已经包含了我一直使用的html电子邮件脚本。希望它有所帮助。

<?php
$myFile = "email.html";
$fh = fopen($myFile, 'r');
$htmlemail = fread($fh, filesize($myFile));
fclose($fh);


$to = "YOUREMAIL@gmail.com" . ",";
//$to .= "@gmail.com" . ",";

$subject = "SUBJECT";

$message = $htmlemail;

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";


$headers .= 'From: NAME <email@email.com>' . "\r\n";


// Mail it
mail($to, $subject, $message, $headers);

?>

我想知道邮件订单是否会起作用是否有效:

你有 if ($swift->send($message, $email_to, $email_from_mail))

矿: mail($to, $subject, $message, $headers);

值得一试