Member Offer
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Send Message Error in PHP Wordpress

Discussion in 'Website Coding & Programming Forum:' started by Mohamed Atef, Aug 8, 2017.

  1. Mohamed Atef

    Mohamed Atef New Member

    Welcome Everybody
    Now i Have Problem in my php code In wordpress i had Created Page in PHP to Send Mail from this Page
    After this When i Receive The E-mail From This Page i find The Mail Empty Without Any Information
    Like This Photos
    Thanks
    1.png 2.png
     
  2. bigdave

    bigdave Moderator Staff Member

    Have you turned debugging on in your wp-config.php file? With debugging on, are there any frontend errors when submitting the form?

    Try re-writing your code like this:

    <?php get_header();

    if (isset($_POST['submitted']) ) {
    $to = "your email address";
    $from = $_POST['message_name'];
    $subject = $_POST['message_about'];
    $message = $_POST['message_text'];
    $phone = $_POST['message_phone'];
    $email = $_POST['message_email'];
    $country = $_POST['message_country'];
    $payment = $_POST['message_payment'];
    $headers = "from:" .$from;
    $headers .= 'Reply-To:'. $email . "\r\n";
    $headers .= "X-Mailer: PHP/" . phpversion(); // Sender's Email
    $body = "From: $from\n E-Mail: $email\n Contact Number: $phone\n Country:\n $country Payment:\n $payment Message:\n $message";
    }

    if (isset($_POST['submitted'])) {
    mail ($to, $subject, $body, $headers);
    }
    ?>


    Always a good idea for the get_header(); to be the first declaration in the document.

    Even better idea is to look into using SMTP rather than the php mail() declaration as it's a much more reliable method of delivering mail.
     
    Last edited: Aug 24, 2017
    Mohamed Atef likes this.

Share This Page