5

So, I have been working on this mail function for the last hour or so, but I can't figure out why it is not sending out the email! I have tried multiple times, altering the code and trying to make it perfect, but still, I have not received the test email...

I have HTML in my email, however, that is not the problem, as I have tested it out without the HTML.

MY PHP:

$to = $register_data['email'];
        $subject = "Welcome!";
        $body = '
            <html>
                <head>
                    <style>
                        body{
                            background-color: #FFF;
                            font-family: arial;
                            margin: 0;
                            padding: 0;
                        }
                        a{
                            color: inherit;
                            text-decoration: none;
                        }
                        .outer-email{
                            width: 80%;
                            height: auto;
                            margin: 0 auto;
                        }
                        .info-email{
                            width: 80%;
                            margin: 120px auto;
                        }
                        .outer-header h3{
                            font-size: 2.9em;
                            color: #151515;
                            margin: 0;
                        }
                        .inner-email{
                            margin-top: 20px;
                        }
                        .inner-email span{
                            font-size: 1.3em;
                            color: #151515;
                        }
                    </style>
                </head>
            <body>
                <div class="outer-email">
                    <div class="info-email">
                        <div class="outer-header">
                            <h3>Welcome!</h3>
                        </div>
                        <div class="inner-email">
                            <span>Welcome, $register_data['fname'];
                            </span>
                        </div>
                    </div>
                </div>
            </body>
            </html>
        ';
        $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
        $headers .= 'From: Domain <noreply@domain.com>';

        mail($to, 'Welcome!', $body, $headers);

Please don't class this as a duplicate either, because I have tested ALOT of the other forum questions on this topic, and they didn't solve my problem! :(

Thanks

EDIT: My register function on page:

if(empty($_POST) === false && empty($errors) === true) {
            $register_data = array(
                'username'      => $_POST['username'],
                'password'      => $_POST['password'],
                'fname'         => $_POST['fname'],
                'lname'         => $_POST['lname'],
                'email'         => $_POST['email'],
                'type'          => $_POST['type'],
                'email_code'    => md5($_POST['username'] + microtime())
            );
            register($register_data, $conn);
            redirect('register.php?success');
            exit();
        } else if (empty($errors) === false)  {
            echo error_output($errors);
        }

UPDATE::

Ok, so I've figured out that if I upload it onto my published server, It does in fact work, so it must've been a problem on my localhost... Thanks @MarkP

GROVER.
  • 4,071
  • 2
  • 19
  • 66

2 Answers2

3

Ok, After a live chat it turns out the OP is using a local server (XAMPP).

I recommended they go to How to configure XAMPP to send mail from localhost?

To find out how to activate the mail server.

@Caelan Grgurovic if this is the correct solution, please accept my answer so that people don't spend their time trying to figure out what the issue is.

edit

Try this on your server

new page test.php

<?php
 mail('youremail@email.com', 'Welcome!', 'body');
?>

obv change your email, if this does not work, then you have not set up emails on your server correctly, try on a web host server.

Community
  • 1
  • 1
MarkP
  • 2,546
  • 5
  • 31
  • 48
2

Not sure if it's the case, but you have a syntax error in your $body, change

<span>Welcome, $register_data['fname'];

to

<span>Welcome, '.$register_data["fname"].';
Aung Myo Linn
  • 2,820
  • 3
  • 27
  • 38