0

I am trying to send a mail from a contact form in my website and when it's successfully sent I want to display a success message but the success message shows all the time ,what's a fix for this?

<?php
    $bussiness = $_POST['contact[Business Name]'];
    $ownername = $_POST['ownername'];
    $buyername = $_POST['buyername'];
    $address = $_POST['address'];
    $city = $_POST['city'];
    $state = $_POST['state'];
    $zipcode = $_POST['zipcode'];
    $phone = $_POST['phone'];
    $email = $_POST['email'];
    $yib = $_POST['yib'];
    $nroe = $_POST['nroe'];
    $nol = $_POST['nol'];
    $taxid = $_POST['taxid'];
    $resalelicense = $_POST['resalelicense'];
    $productlines = $_POST['productlines'];
    $retailerlist = $_POST['retailerlist'];



    $formcontent=" From: $bussiness \n OwnerName: $ownername \n Buyer name: $buyername \n Address: $address \n City: $city \n State: $state \n Zip Code: $zipcode \n Phone: $phone \n Email: $email \n Years in bussiness: $yib \n Number of employees : $nroe \n Number of locations: $nol \n Tax ID: $taxid \n Resale license : $resalelicense \n Product lines: $productlines \n Retailer list: $retailerlist ";
    $recipient = "agonramizi@gmail.com";
    $subject = "Contact Form";
    $mailheader = "From: $email \r\n";
    if(mail($recipient, $subject, $formcontent, $mailheader)) {
        echo "Thank you, your message has been recieved!";
    }else {
        echo "Sorry, there was an error sending your message!";
    }
?>

and my html is below,I want to fix it so it only shows the message after it sends the email , here is my website http://hip-products.rogsiteworks.com/contact.php

Thank you

  • Put a conditional around it. – chris85 Oct 31 '17 at 16:02
  • 1
    It's because the `server` marked it as a `success for delivery` **BUT**, Just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination. Once the server says "got it", php gives up with a `success`. Your `if` statement fails if the **server** doesn't accept the mail for outbound. – Zak Oct 31 '17 at 16:02
  • How do I go through this? What's condition do I need? –  Oct 31 '17 at 16:07
  • Visit the dup, you need to check that the `POST` is set before running the mailing. Also verify the `Business Name`, I think that is going to come in as an array. – chris85 Oct 31 '17 at 16:12
  • Thank you, so in my case I should check Post of my form? –  Oct 31 '17 at 16:22
  • Yes, that is correct. – chris85 Oct 31 '17 at 19:04

0 Answers0