dongyi1982 2011-10-20 12:03 采纳率: 0%
浏览 54

有人可以用phpmailer帮助我吗?

I've made a HTML email and everything has worked so far. I was planning to send it with PHP (using the mail(); function). However, when I did this, the mail did not arrive at hotmail and gmail accounts. I googled around a bit and people suggested to use PHPmailer.

I downloaded PHPmailer and installed it on my server. So far, so good. But now I have the following code:

<?php
set_include_path('.:c:\domains\mydomain\wwwroot\phpmailer\phpmailer.inc.php');
set_include_path('.:c:\domains\mydomain\wwwroot\phpmailer\smtp.inc.php');

require("phpmailer.inc.php");


$mail = new PHPMailer();

$mail->IsHTML(true);
$mail->From     = "from@example.com";
$mail->AddAddress("mymail@mydomain.com");

$mail->Subject  = "An HTML Message";
$mail->Body     = "Hello, <b>my friend</b>! 

 This message uses HTML entities!";

if($mail->Send()) {
  echo 'Message is sent';

} else {
  echo 'Message was not sent..';
 echo 'Mailer error: ' . $mail->ErrorInfo;
}
?>

I got several problems:

  • The output tells me the email is not sent, but it is.
  • I get two subjects
  • If I add more html (like a table), it still gets rejected by hotmail (and probably gmail too).

Also, I saw there's a SMTP function. How to use this function? Do I need to write down my own SMTP?

Would be very happy if someone could help me out!

edit:

class SMTP {
    var $SMTP_PORT = 25; # the default SMTP PORT
    var $CRLF = "
";  # CRLF pair

    var $smtp_conn;      # the socket to the server
    var $error;          # error if any on the last call
    var $helo_rply;      # the reply the server sent to us for HELO

    var $do_debug;       # the level of debug to perform

    /*
     * SMTP()
     *
     * Initialize the class so that the data is in a known state.
     */
    function SMTP() {
        $this->smtp_conn = 0;
        $this->error = null;
        $this->helo_rply = null;

        $this->do_debug = 0;
    }
  • 写回答

1条回答 默认 最新

  • douzhongjian0752 2011-10-20 13:00
    关注

    I use PHPMailer in different projects.

    I suggest you to send the mails via SMTP, of course PHPMailer supports it:

    $mail = new PHPMailer();
    $mail->IsSMTP();     // send via SMTP
    $mail->Host = "smtp.gmail.com" //(or the smtp server you use)
    $mail->Port = "465" //(gmail uses secure smtp so that runs on port 465)
    $mail->SMTPAuth  = "true"   //we need to autenticate to the server
    $mail->SMTPSecure = "ssl"  //we use ssl to protected the flow of info
    $mail->Username = "mymail@gmail.com" //account 
    $mail->Password = "password" //password
    
    
    //build the message
     $mail->IsHTML(true);
    $mail->From     = "mymail@gmail.com";
    $mail->AddAddress("mymail@mydomain.com"); //who receives the mail
    $mail->Subject  = "An HTML Message";
    $mail->Body     = "Hello, <b>my friend</b>! 
    
     This message uses HTML entities!";
    
    if($mail->Send()) {
      echo 'Message is sent';
    
    } 
    else {
      echo 'Message was not sent..';
     echo 'Mailer error: ' . $mail->ErrorInfo;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么