Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Please anyone refer this code and correct it for me. I have used this code in another webpage it is working, but now this script is not sending the message, it show my custom error message.

Could you please any one help me to find the problem

Thank you

   <?php

        /* for admin */
        $registration_subject="Live demo registration";
        $registration_office="[email protected]";

        /* REGISTER details */

        $bizname = $_POST['txtbizname'];
        $biztype = $_POST['cbobiztype'];
        $address = $_POST['TxtAddress'];
        $city = $_POST['TxtCity'];
        $country = $_POST['cboCountry'];
        $tel = $_POST['TxtTel'];
        $fax = $_POST['TxtFax'];
        $email = $_POST['TxtEmail'];
        $web = $_POST['TxtWeb'];    
        $title = $_POST['Cbotitle'];
        $contname = $_POST['txtcontname'];
        $designation = $_POST['TxtDesignation'];
        $mob = $_POST['TxtMob'];
        $contemail = $_POST['TxtcontEmail'];
        $callbiztime = $_POST['BizGMT'];


        $body = <<<EOD
    Business Name : $bizname <br>
    Business Type : $biztype <br>
    Address : $address <br>
    City : $city <br>
    Country : $country <br>
    Tel : $tel <br>
    Fax : $fax <br>
    Email : $email <br>
    Web : $web <br>
    Title : $title <br>
    Contact Person Name : $contname <br>
    Designation : $designation <br>
    Mobile : $mob <br>
    Email : $contemail <br>
    Call Me at : $callbiztime <br>

    EOD;


        $headers = "From : $email\r\n";
        $headers = "Content-type:text/html\r\n";
        $mail_status = mail($registration_office, $registration_subject, $body, $headers);

    if ($mail_status) { ?>
        <script language="javascript" type="text/javascript">
            alert('Thank you for the message. We will contact you shortly.');
            window.location = 'b2b.html';
        </script>
    <?php
    }
    else { ?>
        <script language="javascript" type="text/javascript">
            alert('Message failed. Please, send an email to [email protected]');
            windowwindow.location = 'b2b.html';
        </script>
    <?php
    }
    ?>
share|improve this question
It shows the Message failed. Please, send an .... message? Or what "custom error message" do you mean? – sebastian 5 hours ago
Are you testing it on localhost? do you have a SMTP server where you are testing it? – Wallack 5 hours ago
It's problem with your mailing server , not with code. – Yogesh Suthar 5 hours ago
What's the error showing? – Sami Dz Hamida 5 hours ago
@OP: See Christian's answer below, should do 'er. Use this $headers .= "Content-type:text/html\r\n"; - Notice the missing dot? – Fred 2 hours ago

3 Answers

Try setting error_reporting(E_ALL) at the top of your script and check for any error in the page or in your error log. If you still have problems, just post the error you get.

share|improve this answer
it displays "The website encountered an error while retrieving xxxx.com/B2BSolution.php. It may be down for maintenance or configured incorrectly. Here are some suggestions: Reload this webpage later. HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request." – user1138698 5 hours ago
It's a problem with your script (HTTP 500 is sometimes returned when PHP encounters an error). Check carefully your code and put the error_reporting line at the top of that script, too. Post the errors you see. – Giulio Muscarello 5 hours ago
Oh, one thing - if you can't spot the bug, you should post the entire code of B2BSolution.php, so that we can analyze it. – Giulio Muscarello 5 hours ago

Comment your code and just try with some hardcoded values to check if mailing generally works:

mail("[email protected]", "My Subject", "blablabla");

If it does not work, you have a problem with your mailserver

share|improve this answer

You've got:

$headers = "From : $email\r\n";
$headers = "Content-type:text/html\r\n";

You'll want to concatenate the second line onto the first with:

$headers  = "From : $email\r\n";
$headers .= "Content-type:text/html\r\n";

See http://php.net/manual/en/function.mail.php - You need to specify a 'From' address, which will be missing because you're currently replacing it with the 'Content-type' line.

share|improve this answer
Yep, that missing (dot) will do it. Good catch. – Fred 2 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.