0

I am using Gmail's SMTP server to send mails for a Checkout form.The HTML has no Errors, But the PHP is giving me the following error when running it on testing server(WAMP64): Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp64\www\phpreal\sendmemail.php on line 27.

Here is my HTML Code:

    <head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">  
  <form id="contact" action="sendmemail.php" method="post">
    <h3>Checkout</h3>
    <h4>Get your reply with in 24 hours!</h4>
    <fieldset>
      <input placeholder="Full Name" type="text" name="name" tabindex="1" required autofocus>
    </fieldset>
    <fieldset>
      <input placeholder="Email Address" type="email" name="email" tabindex="2" required>
    </fieldset>
    <fieldset>
      <input placeholder="Phone Number" type="text" name="subject" tabindex="3" required>
    </fieldset>

    <fieldset>
      <textarea placeholder="Type your Address Here...." name="message" tabindex="5" required></textarea>
    </fieldset>
    <fieldset>
      <button name="submit" type="submit" id="contact-submit" data-submit="...Sending">Submit</button>
    </fieldset>
  </form> 
</div>
</body>

Here is my PHP Code:

<?php session_start();
if(isset($_POST['submit'])) {
$host = "smtp.gmail.com";   //Gmail SMTP Server
$smtp_port = 465;          //Gmail SMTP Port
$smtp_username = 'shaheermkhan786@gmail.com';    //My Gmail
$smtp_password = 'xxxxxxx';    //My Password
$fromsubject = 'Checkout Form';
$name = $_POST['name'];
$mail = $_POST['email'];
$subject = $_POST['subject']; 
$message = $_POST['message']; 
$to = $youremail; 
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type:text/html; charset=UTF-8' . "\r\n";
$headers .= "From: ".$_POST['name']."<".$_POST['Email'].">\r\n"; 
$headers .= "Reply-To: ".$_POST["email"]."\r\n";
$mailsubject = 'Messsage recived for'.$fromsubject.' Checkout Page';
$body = $fromsubject.'

    The person that contacted you is  '.$name.'
     E-mail: '.$mail.'
     Subject: '.$subject.'

     Message: 
     '.$message.'   
    |---------END MESSAGE----------|'; 
echo "Thank you fo your feedback. I will contact you shortly if needed.<br/>Go to <a href='/index.php'>Home Page</a>"; 
                                mail($to, $subject, $body,$headers);
 } else { 
echo "You must write a message. </br> Please go to <a href='/index.html'>Home Page</a>"; 
}
?> 

My Website I am Doing This For: valueitem.store

ShaheerDevOps
  • 51
  • 1
  • 1
  • 7
  • NOTE: Never call anything `name="submit"` in a form. Change the name in the form and the php POS test – mplungjan Jun 12 '20 at 13:41
  • I would HIGHLY recommend switching to a library like [PHPMailer](https://github.com/PHPMailer/PHPMailer). `mail()` can't do the necessary work – Machavity Jun 12 '20 at 13:46
  • https://stackoverflow.com/questions/16048347/unable-to-send-email-using-gmail-smtp-server-through-phpmailer-getting-error-s – Machavity Jun 12 '20 at 13:51

0 Answers0