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 <[email protected]>';

        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

23
  • are you getting any errors? Commented Jan 31, 2016 at 5:57
  • @MarkP none, I have made sure to turn error reporting off Commented Jan 31, 2016 at 5:57
  • How are you getting this? $register_data['email']; ? Commented Jan 31, 2016 at 5:58
  • @MarkP from the register form on the other page... Would you like me to show? Commented Jan 31, 2016 at 5:58
  • try the mail function at the bottom with a hard coded email first mail('[email protected]', 'Welcome!', $body, $headers); do you get an email? Commented Jan 31, 2016 at 5:58

2 Answers 2

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('[email protected]', '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.

Sign up to request clarification or add additional context in comments.

2 Comments

didn't work, sorry :(
I'll try this... see how it goes :/
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"].';

6 Comments

What's the difference?
you are not escaping the single quote surrounding fname
@CaelanGrgurovic: One difference is that it is using string concatenation whereas the your code isn't.
@Kolunar already done this in the real code, I've just shrunk the original HTML down and forgot to concatenate..
shouldnt be a problem with his issue at the moment as he said he tried it without all that, and the mail function still didnt send.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.