为什么不发送电子邮件标题:没有回复?

时间:2016-06-08 21:43:25

标签: php html

我有一个网站的人注册成为用户。

此脚本向用户发送一个注册它们的按钮。我的问题是他们的电子邮件仍然说FROM:example@server.example.com

我怎么说它来自no-reply@example.com我可以发誓这会在标题中起作用

$头[ “回复”] = “no-reply@example.com”;

有人可以帮助我吗?

<?php

class SignupEmail {

public function sendEmail($name, $email){

  $admin_email = "test@gmail.com";

  // request the fields needed for email from form

  $subject = "New User!";
  // request field for bots
  $subjectUser = "New User!";



  //capitalize the first letter of the first name
  $name = ucfirst($name);

  //user information
  $to = $email;
  $subjects = "Thanks " . $name . ", for signing up.";
  $messages='<html>
            <head>
            <style>
            #copyw{position:absolute;bottom:0;}
            #logo{background-color:white;width:100%;height:150px;}
            body{background-image: url("https://www.example.com/images/emailbg.png");no-repeat center center fixed; 
              -webkit-background-size: cover;
              -moz-background-size: cover;
              -o-background-size: cover;
              background-size: cover;
            }
            button{
              color:white;
              background-color:green;
            }

            </style>
            <title>Welcome to Example!</title>
            </head>
            <body>
            <tr id="logo">
            <img src="https://www.example.com/example-logo-dark.png">
            </tr>
            <h1 style="color:white;font-size:35px;font-weight:bold;">Thank you for Signing up!</h1>
            <h2 style="color:white; font-size:30px;">Click the button below to login for the first time.</h2>
            <a href="https://www.example.com/login.php"><img src="https://www.example.com/images/login-img.png" height="175" width="140" /></a>
            <form action="https://www.example.com">
              <input type="submit" value="Login!">
            </form>
            <table>
            <tr>

            </tr>
            <tr>
            <td style="font-size:22px;font-color:gray;" id="copyw">&copy; example 2016. All rights reserved. </td>
            </tr>
            </table>
            </body>
            </html>';

  $headers  = 'MIME-Version: 1.0' . "\r\n";
  $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  $headers["Reply-To"]="no-reply@example.com";


   if (!mail($to, $subjects, $messages, $headers) || !mail($admin_email, $email, $name)){

return 'Mailfailure';   

    }
else {
return 'Mailsent';
}



}
}
?>

1 个答案:

答案 0 :(得分:2)

$headers变量必须是一个字符串,其中每个标题都是一行。但是你将它视为一个数组:

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers["Reply-To"]="no-reply@example.com";
        ^^^^^^^^^^^^

您应该将其更改为:

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "Reply-To: no-reply@example.com\r\n"; // or
$headers .= "From: no-reply@example.com\r\n";
相关问题