-1

I have some HTML/PHP code. When I upload it to my site, click the send email button, it just sits there.... Why?

HTML

<form class="contact-form" action="contactform.php" method="post"></form>
                                                <input type="text" name="name" placeholder="Full Name">
                                                <input type="text" name="mail" placeholder="Your e-mail address">
                                                <input type="text" name="subject" placeholder="Subject">
                                                <textarea name="message" placeholder="Message"></textarea>
                                                <button type="submit" name="submit">SEND MAIL</button>
                                            </form>

PHP

<?php

if(isset($_POST['submit'])) {
    $name = $_POST['name'];
    $subject = $_POST['subject'];
    $mailFrom = $_POST['mail'];
    $message = $_POST['message'];

    $mailTo = "Support@Kentuckianabowler.com";
    $headers = "From: ".$mailFrom;
    $txt = "You have received an e-mail from ".$name.".\n\n".$message;

    mail($mailTo, $subject, $txt, $headers);

    header("Location: index.html?mailsend");

}

?>
  • Either there is an error you just need to enable error reporting, or your POST is not working so you never access the if statement – pr1nc3 Jan 29 '19 at 09:53

2 Answers2

0

As @pr1nc3 said make sure the variables are there first by doing var_dump($_POST) inside your if statement, if all the variables exist try the following:

$uid = md5(uniqid(time()));

$headers = "From: " . $mailFrom . "\r\n";
$headers .= "Reply-To: " . $mailFrom . "\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n";

$txt= "--".$uid."\r\n";
$txt.= "Content-type:text/html; charset=UTF-8" . "\r\n";
$txt.= "You have received an e-mail from ".$name.".\n\n".$message;

mail($mailTo, $subject, $txt, $headers);
Paddy Hallihan
  • 1,624
  • 3
  • 27
  • 76
0

You can send mail from localhost with sendmail package , sendmail package is inbuild in XAMPP. So if you are using XAMPP then you can easily send mail from localhost.

for example you can configure C:\xampp\php\php.ini and c:\xampp\sendmail\sendmail.ini for gmail to send mail.

in C:\xampp\php\php.ini find extension=php_openssl.dll and remove the semicolon from the beginning of that line to make SSL working for gmail for localhost.

in php.ini file find [mail function] and change

SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = my-gmail-id@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

Now Open C:\xampp\sendmail\sendmail.ini. Replace all the existing code in sendmail.ini with following code

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=my-gmail-id@gmail.com
auth_password=my-gmail-password
force_sender=my-gmail-id@gmail.com

Now you have done!! create php file with mail function and send mail from localhost.

PS: don't forgot to replace my-gmail-id and my-gmail-password in above code. Also, don't forget to remove duplicate keys if you copied settings from above. For example comment following line if there is another sendmail_path : sendmail_path= "C:\xampp\mailtodisk\mailtodisk.exe" in the php.ini file

Also remember to restart the server using the XAMMP control panel so the changes take effect.

For gmail please check https://support.google.com/accounts/answer/6010255 to allow access from less secure apps.

shreyash
  • 1
  • 1
  • 5