doudun8705 2017-01-04 08:23
浏览 62

使用PHP打开电子邮件后收到警告消息

I am using PHPMailer for sending an email. Emails are getting proper but whenever I am opening email which I was sent using PHP Mailer I am getting a warning message.

Note: If I remove anchor tag from $phpMailerText then I am not getting any warning.If I add anchor tag then I am getting warning.Would you help me in this?

enter image description here

require 'mail/PHPMailerAutoload.php';
    $to = $email;
    //Create a new PHPMailer instance
    $mail = new PHPMailer;

    //Enable SMTP debugging
    // 0 = off (for production use)
    // 1 = client messages
    // 2 = client and server messages
    $mail->SMTPDebug = 0;

    //Ask for HTML-friendly debug output
    $mail->Debugoutput = 'html';

    // Headers 
$headers = "Content-Type: text/plain; charset=\"utf-8\"
"
              . "X-mailer: smtp.gmail.com" . "
" // this will identify the real sender
              . "Precedence: bulk" . "
" // this will say it is bulk sender
              .  "List-Unsubscribe:abc@gmail.com
" // this will reveal the OPT-OUT address
                . "Reply-To: $to
"
                . "To: $to
"
                . "From: $to
";

    //Set the hostname of the mail server
    $mail->Host = 'smtp.gmail.com';

    //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
    $mail->Port = 587;

    //Set the encryption system to use - ssl (deprecated) or tls
    $mail->SMTPSecure = 'tls';

    //Whether to use SMTP authentication
    $mail->SMTPAuth = true;

    //Username to use for SMTP authentication - use full email address for gmail
    $mail->Username = "abc@gmail.com";

    //Password to use for SMTP authentication
    $mail->Password = "****";

    //Set who the message is to be sent from
    $mail->setFrom('abc@gmail.com', 'code');

    //Set an alternative reply-to address
    $mail->addReplyTo('abc@gmail.com', 'code');

    //Set who the message is to be sent to
    $mail->addAddress($to, 'Customer');

    //Set the subject line
    $mail->Subject = 'code';

    $phpMailerText="<!DOCTYPE HTML><html>
    <head>
    <title>HTML email</title>
    </head>
    <body>

    <a href='http://www.companyname.com/changepassword.php?user_id=" .$User_id1."'>Create your password here</a>
    </body>
    </html>";

    $mail->msgHTML($phpMailerText);

    //Replace the plain text body with one created manually
    $mail->AltBody = ' ';

    //send the message, check for errors
    if (!$mail->send()) { echo "Mailer Error: " . $mail->ErrorInfo;
    } else {  
    }
  • 写回答

2条回答 默认 最新

  • douxiajia6309 2017-01-04 08:32
    关注

    Try the following code and do the other steps.

    1. Create reverse dns record
    2. Configure SPF records
    $to = $email;
    //Create a new PHPMailer instance
    $mail = new PHPMailer;
    
    //Enable SMTP debugging
    // 0 = off (for production use)
    // 1 = client messages
    // 2 = client and server messages
    $mail->SMTPDebug = 0;
    
    //Ask for HTML-friendly debug output
    $mail->Debugoutput = 'html';
    
    // Headers 
    $headers = "Content-Type: text/plain; charset=\"utf-8\"
    "
                  . "X-mailer: YOUR_SITE_DOMAIN Server" . "
    " // this will identify the real sender
                  . "Precedence: bulk" . "
    " // this will say it is bulk sender
                  .  "List-Unsubscribe:info@YOUR_SITE_DOMAIN
    " // this will reveal the OPT-OUT address
                    . "Reply-To: $email
    "
                    . "To: $email
    "
                    . "From: $email
    ";
    
    $mail->addCustomHeader( $headers );
    
    //Set the hostname of the mail server
    $mail->Host = 'smtp.gmail.com';
    
    //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
    $mail->Port = 587;
    
    //Set the encryption system to use - ssl (deprecated) or tls
    $mail->SMTPSecure = 'tls';
    
    //Whether to use SMTP authentication
    $mail->SMTPAuth = true;
    
    //Username to use for SMTP authentication - use full email address for gmail
    $mail->Username = "me@companydomain.com";
    
    //Password to use for SMTP authentication
    $mail->Password = "****";
    
    // Because html is being used
    $mail->isHTML(true);
    
    //Set who the message is to be sent from
    $mail->setFrom('me@companydomain.com', 'code');
    
    //Set an alternative reply-to address
    $mail->addReplyTo('me@companydomain.com', 'code');
    
    //Set who the message is to be sent to
    $mail->addAddress($to, 'Customer');
    
    //Set the subject line
    $mail->Subject = 'code';
    
    $phpMailerText="<!DOCTYPE HTML><html>
    <head>
    <title>HTML email</title>
    </head>
    <body>
    
    <a href='http://www.companyname.com/changepassword.php?user_id=" .$User_id1."'>Create your password here</a>
    </body>
    </html>";
    
    $mail->msgHTML($phpMailerText);
    
    //Replace the plain text body with one created manually
    $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; 
    
    //send the message, check for errors
    if (!$mail->send()) { echo "Mailer Error: " . $mail->ErrorInfo;
    } else {  
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私