0

index page

<?php 
    $result = "";
    $result = "";
    $error  = "";
if(isset($_POST['submit']))
{
    require 'phpmailer/PHPMailerAutoload.php';
    $mail = new PHPMailer;
    //smtp settings
    $mail->isSMTP(); // send as HTML
    $mail->Host = 'smtp.gmail.com'; // SMTP servers
    $mail->SMTPAuth = true; // turn on SMTP authentication
    $mail->Username = 'elfatihnadir@gmail.com'; // Your mail
    $mail->Password = 'fifaunique7914'; // Your password mail
    $mail->Port = 587; //specify SMTP Port
    $mail->SMTPSecure = 'tls';                               
    $mail->setFrom($_POST['email'],$_POST['name']);
    $mail->addAddress('elfatihnadir@gmail.com');
    $mail->addReplyTo($_POST['email'],$_POST['name']);
    $mail->isHTML(true);
    $mail->Subject='Form Submission:' .$_POST['subject'];
    $mail->Body='<h3>Name :'.$_POST['name'].'<br> Email: '.$_POST['email'].'<br>Message: '.$_POST['message'].'</h3>';
    if(!$mail->send())
    {
        $error = "Something went wrong. Please try again.";
    }
    else 
    {
        $result="Thanks\t" .$_POST['name']. " for contacting us.";
    }
}


?>


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Contact Form</title>
<link href="https://fonts.googleapis.com/css?family=Roboto|Courgette|Pacifico:400,700" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 

<link rel="stylesheet" href="styles.css">

</head>

<body>
    <div class="container">
        <div class="row">
            <div class="col-md-8 col-md-offset-2 m-auto">
                <div class="contact-form">
                    <h1>Contact Form SendMail</h1>
                    <h2 class="text-center text-white"> <?=$result; ?></h2>
                    <h2 class="text-center text-danger"> <?=$error; ?></h2>
                    <form action="" method="post">
                        <div class="row">
                            <div class="col-sm-6">
                                <div class="form-group">
                                    <label for="inputName">Name</label>
                                    <input type="text" class="form-control" id="Name" name="name" placeholder="Enter Full" required>
                                </div>
                            </div>
                            <div class="col-sm-6">
                            <div class="form-group">
                                <label for="inputEmail">Email</label>
                                <input type="email" class="form-control" id="Email" name="email" placeholder="Enter Email" required>
                            </div>
                        </div>
                    </div>            
                    <div class="form-group">
                        <label for="inputSubject">Subject</label>
                        <input type="text" class="form-control" id="Subject" name="subject" placeholder="Enter Subject" required>
                    </div>
                    <div class="form-group">
                        <label for="inputMessage">Message</label>
                        <textarea class="form-control" id="Message" name="message" rows="5" placeholder="Enter Message..." required></textarea>
                    </div>
                    <div class="text-center">
                        <button type="submit" name="submit" class="btn btn-primary"><i class="fa fa-paper-plane"></i> Send</button>
                    </div>            
                </form>
            </div>
        </div>
    </div>
</div>
</body>
</html>  

I am using phpmailer After I click submit,it gives ("Something went wrong. Please try again.";), the question here, the problem might be from the host or not, or does the host affect it? (because am using a free host called InfinityFree) and what about the port number, does it affect the execution?. the final question, what should I do to make this works in your opinion? thanks

ADyson
  • 57,178
  • 14
  • 51
  • 63
Tefa
  • 1
  • 1
  • 1
    Something went "wrong" or maybe "worng". Without an actual error logged it's anyones guess. – l'L'l Feb 05 '20 at 08:20
  • i didnt get u sorry – Tefa Feb 05 '20 at 08:24
  • guys the script works fine but does not send the message – Tefa Feb 05 '20 at 08:24
  • 4
    You said it says "Something went wrong" when you hit submit, I wouldn't say that's "fine". – l'L'l Feb 05 '20 at 08:26
  • 1
    "Something went wrong" is an error message **you** created in the code. It doesn't tell us, or you, anything about what **actually** went wrong. It's unclear why you'd expect us to be able to tell you much from a made-up message? All we know from that is that `send()` failed. Looking at the contents `$mail->ErrorInfo` would be likely to give you some more detailed information to work with. https://github.com/PHPMailer/PHPMailer has a simple example of how to use that properly in a try/catch block. – ADyson Feb 05 '20 at 08:38
  • Or you might be able to use it like this example: https://stackoverflow.com/a/6342349/5947043 . I'm sure you can google some more info about how to handle errors in PHPMailer, there is no shortage of information! Did you try to find anything out?? P.S. here's a good general guide to debugging email problems in PHP: https://stackoverflow.com/a/24644450/5947043 – ADyson Feb 05 '20 at 08:41
  • Once you have some useful error information for us to look at, we might be more able to help you solve the problem (assuming you can't already fix it yourself, based on what you discovered). The basic lesson here is to do some proper error handling and proper debugging of your program. It's fine to display a generic message like "something went wrong" for the benefit of your users, but that's not useful information to give to other programmers and technicians when you want some help to solve the underlying issue. – ADyson Feb 05 '20 at 08:45
  • thanks for the explanation, i am new, i apologize – Tefa Feb 05 '20 at 10:00
  • No need to apologise. But in future just consider whether _you_ would be able to solve a problem in someone else's code without any technical or error information :) – ADyson Feb 05 '20 at 11:25
  • One other thing: you're using a very old version of PHPMailer. [Get the latest](https://github.com/PHPMailer/PHPMailer). While you're there, it's always a good idea to [read the troubleshooting guide](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting) to resolve problems like this. – Synchro Feb 05 '20 at 17:51

0 Answers0