0

Im trying to send mail from my localhost but it doesn't work. I change settings on SMTP but it still doesnt send.

here is my code for html

<html>
<head>
<title>Subscribe</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>

<li><a href="admin.php">Admin</a></li>
<li> <a href="index.php">Home<a></li>

<form  action="email.php" method="post">
    name : <input action="email.php" class="name" type="text" name="username">
        <br>

    email : <input class="email" type="text" name="email">
        <br>
        <input name="submit" type="submit" value="insert">
</form>


</body>
</html>

here is my code for php

<?php
    $con = mysqli_connect('127.0.0.1', 'root', '');
    if(!$con) {
        echo "not connected to server";
    }

    if(!mysqli_select_db($con, "task")) {
        echo "database not conncted";
    }

    $Name=$_POST["username"];
    $Email=$_POST["email"];

    $sql = "insert into person (Name,Email) VALUES ('$Name','$Email')";

    if(!mysqli_query($con, $sql)) {
        echo "error!!!!!";

    }



$msg = <<<EMAIL
Hello $Name
Thank you!! You Have Subscribe To Us.
EMAIL;
$subject = "Welcome Massage";

if ($_POST['submit']) {
    $success = mail($Email, $subject, $msg);
    if($success)
    { 
        echo '
        <p>Your message has been sent!</p>
        ';
    } else { 
        echo '
        <p>Something went wrong, go back and try again!</p>
        '; 
    }
}
    header ("refresh:2; url=index.php");




?>

here is what i change for php.ini

SMTP = smtp.gmail.com
 smtp_port =  465

; For Win32 only.
; http://php.net/sendmail-from
 sendmail_from = xxxxxxx@gmail.com

; XAMPP IMPORTANT NOTE (1): If XAMPP is installed in a base directory with spaces (e.g. c:\program filesC:\xampp) fakemail and mailtodisk do not work correctly.
; XAMPP IMPORTANT NOTE (2): In this case please copy the sendmail or mailtodisk folder in your root folder (e.g. C:\sendmail) and use this for sendmail_path.  
; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder)
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the C:\xampp\mailoutput folder
; sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"

and here is what i changed in sendmail.ini

smtp_server=smtp.gmail.com

; smtp port (normally 25)

smtp_port=465

smtp_ssl=SSL

auth_username=myEmail@gmail.com
auth_password=myPass

and it still doesnt work. Please help

alex
  • 17
  • 1
  • 7
  • When you ask a question it's better if you can simplify your code as much as possible and take out anything that isn't relevant to the problem. Also instead of saying it "doesn't work" it's good to describe what you were expecting to happen and what actually happened instead. – bdsl Jul 08 '16 at 21:25
  • Have you enabled the setting on your Gmail account "Allow less secure apps to access your account"? Otherwise emails sent from your localhost won't go through. – awl19 Jul 08 '16 at 21:53

0 Answers0