Drew Peer
Drew Peer

Reputation: 377

Why doesn't email header send from: No reply?

I have a website people sign up as a user.

This script sends the user a button that registers them. My problem is their email still says FROM: [email protected]

How do I make it say FROM [email protected] I could have sworn this would have worked in the headers

$headers["Reply-To"]="[email protected]";

Can someone help me here?

<?php

class SignupEmail {

public function sendEmail($name, $email){

  $admin_email = "[email protected]";

  // 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"]="[email protected]";


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

return 'Mailfailure';   

    }
else {
return 'Mailsent';
}



}
}
?>

Upvotes: 1

Views: 1163

Answers (1)

Dennis B.
Dennis B.

Reputation: 1577

The $headers variable has to be a string where each header is a single line. But you are treating it as an array:

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

You should change it to this:

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "Reply-To: [email protected]\r\n"; // or
$headers .= "From: [email protected]\r\n";

Upvotes: 2

Related Questions