-1

thanks for taking a look at this post.

I have created an HTML/PHP form which should take all the form data and send it to myself and the author.

There are 19 inputs on the form and when I first initially started testing the form sent the email no problem, but for some reason now it will not send at all.

I have added the address the form uses to send the email to our white-list and also tried other email providers to receive the mail but still nothing.

Here is the PHP:

    <?php
if(isset($_POST['submit']))
 {
    $author = $_POST['author'];
    $to = "MY EMAIL ADDRESS, $author"; 
    $from = "FROM ADDRESS"; 
    $title = $_POST['title'];
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $dept = $_POST['dept'];
    $job = $_POST['job'];
    $signature = $_POST['signature'];
    $manager = $_POST['manager'];
    $location = $_POST['location'];
    $start = $_POST['start'];
    $nwc = $_POST['nwc'];
    $vdq = $_POST['vdq'];
    $phone = $_POST['phone'];
    $login = $_POST['login'];
    $domain = $_POST['domain'];
    $password = $_POST['password'];
    $otheremail = $_POST['email'];
    $emailgroups = $_POST['disgroup'];
    $access = $_POST['access'];
    $otheraccess = $_POST['calendar'];

    $subject = "New Starter";
    $message = "Here is the new starter details" . "\n\n" . 

        "Hi Supoprt we have a new starter, here is the information: \n\n" .
        "Title: " . $title . "\n\n" . 
        "First Name: " . $first_name . "\n\n" .
        "Last Name: " . $last_name . "\n\n" .
        "Department: " . $dept . "\n\n" .
        "Job Title: " . $job . "\n\n" . 
        "Signature: " . $signature . "\n\n" .
        "Manager: " . $manager . "\n\n" .
        "Location: " . $location . "\n\n" .
        "Start date: " . $start . "\n\n" .
        "Now We Comply: " . $nwc . "\n\n" .
        "VDQ: " . $vdq . "\n\n" .
        "Phone Required: " . $phone . "\n\n" .
        "AD Login: " . $login . "\n\n" .
        "Domain Name: " . $domain . "\n\n" .
        "Password: " . $password . "\n\n" . 
        "Other Emails: " . $otheremail . "\n\n" .
        "Email Groups: " . $emailgroups . "\n\n" . 
        "Drive & Folder Access: " . $access . "\n\n" .
        "Calendar/Inbox Access: " . $otheraccess . "\n\n"
        . isset($_POST['message']);

    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$subject,$message,$headers);
    echo "Mail Sent. Thank you " . $author . ", we will contact you shortly.";
    }
?>

I am new to PHP so any help would be appreciated.

Kaushal shah
  • 557
  • 3
  • 12
  • In my experience, when this sort of issue happens it can be down the the content of the form fields. A simple apostrophe that's been entered, for example, can cause trouble. Id sanitise your form fields prior to processing. – Will Aug 13 '19 at 12:08
  • 3
    You should look at using something like PHPMailer() rather than the in-built php `mail()` function. There's a bit of a learning curve, though there is a lot of help available, but I believe it is much more reliable than `mail()` is. As @Will said, you should also sanitise and check that your form variables are filled in before blindly using them, to deal with "undefined index" and other issues. Do you really mean to just add "true" or "false" on the very end of the message body with your `isset()` call? – droopsnoot Aug 13 '19 at 12:14

1 Answers1

0

PHPMailer is a class library for PHP that provides a collection of functions to build and send email messages. PHPMailer supports several ways of sending email: mail(), Sendmail, qmail & direct to SMTP servers. You can use any feature of SMTP-based e-mail, multiple recepients via to, CC, BCC, etc. In short: PHPMailer is an efficient way to send e-mail within PHP.

https://github.com/PHPMailer/PHPMailer/wiki/Tutorial