-2

I'm try to send email with html5 template, my code is also working but it shows warning message

Notice: Undefined variable: message in C:\xampp\htdocs\farming.com\mailconfig.php on line 2

<?php
    $message.='<!DOCTYPE>';
    $message.='<html xmlns="http://www.w3.org/1999/xhtml">';
    $message.='<head>';
    $message.='<meta name="viewport" content="width=device-width" />';
    $message.='<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
    $message.='<style>
          * {
      margin: 0;
      padding: 0;
      font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;
      box-sizing: border-box;
      font-size: 14px;
    }

    img {
      max-width: 100%;
    }

    body {
      -webkit-font-smoothing: antialiased;
      -webkit-text-size-adjust: none;
      width: 100% !important;
      height: 100%;
      line-height: 1.6;
    }';
$message.='</head><body><table class="body-wrap"><tr><td></td><td class="container" width="600"><div class="content"><table class="main" width="100%" cellpadding="0" cellspacing="0"><tr><td class="alert alert-warning">Farmingarms</td></tr><tr><td class="content-wrap"><table width="100%" cellpadding="0" cellspacing="0"><tr><td class="content-block">Hi '.$name.',<br>Your login password has been changed.</td></tr><tr><td class="content-block"> If you believe this is an error, please click on the button below to visit our support portal, through which you can contact our support team</tr></td><br><tr><td class="content-block"><a style="color:white;" href='.$actual_link.' class="btn-primary">Contact Us</a></td></tr><br><tr><td class="content-block">Thanks for choosing Farming.</td></tr></table></td></tr></table><div class="footer"><table width="100%"><tr><td class="aligncenter content-block"><a href="www.farmingarms.com">Unsubscribe</a> from these alerts.</td></tr></table></div></div></td><td></td></tr></table></body></html>';
        if(mail($to, $subject, $message, $headers)){
            $error = "mail sended successfully";
}
?>
Balaji Rajendran
  • 357
  • 5
  • 17
  • you can post comment instead of answer for one liner – Sanu0786 Oct 26 '18 at 09:46
  • 1
    Possible duplicate of ["Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP](https://stackoverflow.com/questions/4261133/notice-undefined-variable-notice-undefined-index-and-notice-undefined) – gp_sflover Oct 26 '18 at 09:52
  • @gp_sflover To my extreme surprise, no where on that massive suggested dupe page is there an example of `.=` being used -- so it is poorly suited for this closure. – mickmackusa Oct 26 '18 at 09:56
  • @mickmackusa Interesting. I haven't the time now, but don't you think it would be the case to add an example to the dupe? – gp_sflover Oct 26 '18 at 10:01
  • Possible duplicate of [Undefined variable when declaring with concatenation](https://stackoverflow.com/questions/29359427/undefined-variable-when-declaring-with-concatenation) – mickmackusa Oct 26 '18 at 10:34
  • and https://stackoverflow.com/q/10605842/2943403 and https://stackoverflow.com/q/35345747/2943403 – mickmackusa Oct 26 '18 at 10:35

1 Answers1

2
$message.='<!DOCTYPE>';

In the line above there is an undefined variable warning error in your code. warning error can be ignored they are not critical errors that is why your code is working. click here to read more about PHP errors. "In PHP '.' is the sign of ConCatination"

Explaination $message.='<!DOCTYPE>'; means your are concatinating '<!DOCTYPE>' in the variable $message, your first Need to define the variable $message.

You can do it either by just writing $message=""; in the start of your code or you can also start like $message='<!DOCTYPE>'; like the above answers.

Sayed Mohd Ali
  • 2,156
  • 3
  • 12
  • 28